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

export default defineComponent({
  name: 'skeleton-modal',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    showCount: {
      type: Array,
      default: () => [1, 2, 3, 4, 5]
    }
  },
  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))`,
                overflow: 'hidden',
                width: '100%'
              }}>
              {props.showCount.map(() => (
                <Cell center>
                  {{
                    icon: () => (
                      <div class={styles.iconGroup}>
                        <SkeletonImage class={styles.iconStudent} />
                      </div>
                    ),
                    title: () => (
                      <div class={styles.userInfo}>
                        <SkeletonParagraph
                          class={styles.name}
                          rowWidth={'60%'}
                        />
                        <SkeletonParagraph rowWidth={'40%'} />
                      </div>
                    ),
                    value: () => (
                      <div class={styles.after} style={{ width: '80px' }}>
                        <SkeletonParagraph rowWidth={'100%'} />
                      </div>
                    )
                  }}
                </Cell>
              ))}
            </div>
          ),
          default: () => slots.default && slots.default()
        }}
      </Skeleton>
    );
  }
});
