import { Cell, CellGroup, Skeleton, 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]
    },
    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: props.isLink
                  ? `calc(100vh - var(--header-height))`
                  : 'auto',
                overflow: 'hidden',
                width: '100%'
              }}>
              {props.showCount.map(() => (
                <>
                  {/* <SkeletonParagraph rowWidth={'20%'} class={styles.pTitle} /> */}

                  <CellGroup inset class={styles.pCellGroup}>
                    <Cell center>
                      {{
                        title: () => (
                          <SkeletonParagraph
                            class={styles.title}
                            rowWidth={'60%'}
                          />
                        ),
                        value: () => (
                          <SkeletonParagraph
                            class={styles.time}
                            rowWidth={'30%'}
                          />
                        )
                      }}
                    </Cell>
                    <Cell
                      center
                      class={styles.moreCell}
                      valueClass={styles.valueClass}>
                      <SkeletonParagraph class={styles.item} rowWidth={'90%'} />
                      <SkeletonParagraph class={styles.item} rowWidth={'90%'} />
                      <div class={styles.photoList}>
                        <SkeletonParagraph class={styles.photo} />
                        <SkeletonParagraph class={styles.photo} />
                        <SkeletonParagraph class={styles.photo} />
                        <SkeletonParagraph class={styles.photo} />
                      </div>
                    </Cell>
                  </CellGroup>
                </>
              ))}
            </div>
          ),
          default: () => slots.default && slots.default()
        }}
      </Skeleton>
    );
  }
});
