import { Cell, Skeleton, SkeletonAvatar, SkeletonParagraph } from 'vant';
import { defineComponent, onMounted, reactive, watch } from 'vue';
import styles from './index.module.less';

export default defineComponent({
  name: 'skeleton-modal',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    showCount: {
      type: Array,
      default: () => [1, 2, 3, 4, 5, 6, 5, 6]
    },
    isLink: {
      type: Boolean,
      default: true
    }
  },
  setup(props, { slots }) {
    const forms = reactive({
      loading: false
    });

    onMounted(() => {
      forms.loading = props.show;
    });

    watch(
      () => props.show,
      () => {
        forms.loading = props.show;
      }
    );
    return () => (
      <Skeleton loading={forms.loading} style="flex-wrap: wrap">
        {{
          template: () => (
            <div
              style={{
                height: props.isLink
                  ? `calc(100vh - var(--header-height))`
                  : 'auto',
                overflow: 'hidden',
                width: '100%'
              }}>
              {props.showCount.map(() => (
                <div class={styles.cellGroup}>
                  <Cell
                    center
                    isLink={props.isLink}
                    clickable={false}
                    class={styles.cell}>
                    {{
                      icon: () => <SkeletonAvatar class={styles.iconTeacher} />,

                      title: () => (
                        <div class={styles.username} style={{ width: '80px' }}>
                          <SkeletonParagraph rowWidth={'50%'} />
                          <SkeletonParagraph
                            style={{
                              marginTop: '4px'
                            }}
                          />
                        </div>
                      ),
                      value: () => (
                        <div
                          class={[
                            styles.attendance,
                            !props.isLink ? styles.noLink : ''
                          ]}>
                          <div class={[styles.attendanceItem]}>
                            <SkeletonParagraph
                              class={styles.value}
                              rowWidth={'40%'}
                            />
                            <SkeletonParagraph
                              class={styles.value}
                              rowWidth={'40%'}
                            />
                          </div>
                          <div class={[styles.attendanceItem]}>
                            <SkeletonParagraph
                              class={styles.value}
                              rowWidth={'40%'}
                            />
                            <SkeletonParagraph
                              class={styles.value}
                              rowWidth={'40%'}
                            />
                          </div>
                        </div>
                      )
                    }}
                  </Cell>
                </div>
                // <CellGroup class={styles.cellGroup}>
                //   <Cell center>
                //     {{
                //       icon: () => <SkeletonAvatar class={styles.iconMusic} />,
                //       title: () => (
                //         <div
                //           style={{
                //             display: 'flex',
                //             justifyContent: 'space-between'
                //           }}>
                //           <SkeletonParagraph rowWidth={'40%'} />
                //           <SkeletonParagraph
                //             style={{
                //               marginTop: 0
                //             }}
                //             rowWidth={'40%'}
                //           />
                //         </div>
                //       )
                //     }}
                //   </Cell>
                //   <Cell center class={styles.username}>
                //     {{
                //       icon: () => <SkeletonAvatar class={styles.iconTeacher} />,
                //       title: () => (
                //         <div>
                //           <SkeletonParagraph rowWidth={'40%'} />
                //           <SkeletonParagraph
                //             rowWidth={'40%'}
                //             style={{ marginTop: '4px' }}
                //           />
                //         </div>
                //       )
                //     }}
                //   </Cell>
                // </CellGroup>
              ))}
            </div>
          ),
          default: () => slots.default && slots.default()
        }}
      </Skeleton>
    );
  }
});
