import {
  Cell,
  CellGroup,
  Grid,
  GridItem,
  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%'
              }}>
              {props.showCount.map(() => (
                <CellGroup
                  class={styles['data-content']}
                  border={false}>
                  <Cell center>
                    {{
                      title: () => (
                        <div class={styles.teacher_info}>
                          <SkeletonAvatar class={styles.logo} />
                          <p class={styles.userName} style={{ width: '100px' }}><SkeletonParagraph rowWidth={'50%'} /></p>
                        </div>
                      ),
                      default: () => (
                        <p class={styles.orchestraName}>
                          <SkeletonParagraph />
                        </p>
                      )
                    }}
                  </Cell>
                  <Cell isLink clickable={false} center>
                    {{
                      title: () => (
                        <Grid border={false} columnNum={4} clickable>
                          <GridItem>
                            {{
                              text: () => <SkeletonParagraph rowWidth={'50%'} />
                            }}
                          </GridItem>
                          <GridItem>
                            {{
                              text: () => <SkeletonParagraph rowWidth={'50%'} />
                            }}
                          </GridItem>
                          <GridItem>
                            {{
                              text: () => <SkeletonParagraph rowWidth={'50%'} />
                            }}
                          </GridItem>
                          <GridItem>
                            {{
                              text: () => <SkeletonParagraph rowWidth={'50%'} />
                            }}
                          </GridItem>
                        </Grid>
                      )
                    }}
                  </Cell>
                </CellGroup>
              ))}
            </div>
          ),
          default: () => slots.default && slots.default()
        }}
      </Skeleton>
    );
  }
});
