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]
    }
  },
  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 inset class={styles.detailCellGroup}>
                  <Cell
                    center
                    border={false}
                    class={[styles.className, styles.skeletionTitle]}>
                    {{
                      title: () => <SkeletonParagraph rowWidth={'50%'} />,
                      value: () => <SkeletonParagraph />
                    }}
                  </Cell>
                  <Cell center>
                    <div class={styles.detailGroup}>
                      <div class={styles.detailItem}>
                        <div class={styles.detailStatus}>
                          <SkeletonParagraph rowWidth={'40%'} />
                          <SkeletonAvatar class={styles.img} />
                        </div>
                        <div class={styles.sign}>
                          <SkeletonParagraph rowWidth={'40%'} />
                          <SkeletonParagraph rowWidth={'40%'} />
                        </div>
                      </div>
                      <div class={styles.detailItem}>
                        <div class={styles.detailStatus}>
                          <SkeletonParagraph rowWidth={'40%'} />
                          <SkeletonAvatar class={styles.img} />
                        </div>
                        <div class={styles.sign}>
                          <SkeletonParagraph rowWidth={'40%'} />
                          <SkeletonParagraph rowWidth={'40%'} />
                        </div>
                      </div>
                      <div class={styles.detailItem}>
                        <div class={styles.detailStatus}>
                          <SkeletonParagraph rowWidth={'40%'} />
                          <SkeletonAvatar class={styles.img} />
                        </div>
                        <div class={styles.sign}>
                          <SkeletonParagraph rowWidth={'40%'} />
                          <SkeletonParagraph rowWidth={'40%'} />
                        </div>
                      </div>
                      <div class={styles.detailItem}>
                        <div class={styles.detailStatus}>
                          <SkeletonParagraph rowWidth={'40%'} />
                          <SkeletonAvatar class={styles.img} />
                        </div>
                        <div class={styles.sign}>
                          <SkeletonParagraph rowWidth={'40%'} />
                          <SkeletonParagraph rowWidth={'40%'} />
                        </div>
                      </div>
                    </div>
                  </Cell>
                </CellGroup>
              ))}
            </div>
          ),
          default: () => slots.default && slots.default()
        }}
      </Skeleton>
    );
  }
});
