import {
  Cell,
  CellGroup,
  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]
    }
  },
  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%'
              }}>
              <div class={styles.cellGroup}>
                {props.showCount.map(() => (
                  <CellGroup class={styles.cellGroupIn}>
                    <Cell center clickable={false} class={styles.cell}>
                      {{
                        icon: () => (
                          <SkeletonAvatar class={styles.iconTeacher} />
                        ),

                        title: () => (
                          <div class={styles.username}>
                            <SkeletonParagraph
                              rowWidth={'40%'}
                              style={{ width: '120px' }}
                              class={styles.name}
                            />
                            <SkeletonParagraph
                              rowWidth={'40%'}
                              style={{ width: '120px' }}
                              class={styles.class}
                            />
                          </div>
                        )
                      }}
                    </Cell>
                    <Cell
                      center
                      clickable={false}
                      class={styles.cell}
                      titleClass={styles.cellInfo}>
                      {{
                        title: () => (
                          <div class={styles.info}>
                            <SkeletonParagraph
                              rowWidth={'40%'}
                              class={[styles.times, styles.time1]}
                            />
                            <SkeletonParagraph
                              class={[styles.times]}
                              rowWidth={'40%'}
                            />

                            <SkeletonParagraph
                              class={styles.remark}
                              rowWidth={'100%'}
                            />
                          </div>
                        )
                      }}
                    </Cell>
                  </CellGroup>
                ))}
              </div>
            </div>
          ),
          default: () => slots.default && slots.default()
        }}
      </Skeleton>
    );
  }
});
