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

export default defineComponent({
  name: 'skeleton-modal',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    showCount: {
      type: Array,
      default: () => [1, 2, 3, 4, 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: `calc(100vh - var(--header-height) - var(--van-tabs-line-height))`,
                overflow: 'hidden',
                width: '100%'
              }}>
              {props.showCount.map(() => (
                <CellGroup inset class={styles.cellGroup}>
                  <Cell center class={styles.timerCell} border={false}>
                    {{
                      icon: () => <SkeletonAvatar class={styles.iconTimer} />,
                      title: () => (
                        <div class={styles.timer} style={{ width: '120px' }}>
                          <SkeletonParagraph />
                        </div>
                      ),
                      value: () => (
                        <div class={styles.eStatus}>
                          <SkeletonParagraph rowWidth={'50%'} />
                        </div>
                      )
                    }}
                  </Cell>
                  <Cell center class={styles.usernameCell}>
                    {{
                      icon: () => <SkeletonAvatar class={styles.iconTeacher} />,
                      title: () => (
                        <div>
                          <div class={styles.classname}>
                            <SkeletonParagraph rowWidth={'50%'} />
                          </div>
                          <div class={styles.name} style={{ marginTop: '4px' }}>
                            <SkeletonParagraph rowWidth={'50%'} />
                          </div>
                        </div>
                      ),
                      value: () => (
                        <div class={styles.photoList}>
                          <SkeletonParagraph class={styles.photo} />
                          <SkeletonParagraph class={styles.photo} />
                          <SkeletonParagraph class={styles.photo} />
                        </div>
                      )
                    }}
                  </Cell>
                </CellGroup>
              ))}
            </div>
          ),
          default: () => slots.default && slots.default()
        }}
      </Skeleton>
    );
  }
});
