import { PropType, defineComponent, onMounted, reactive } from 'vue';
import styles from './index.module.less';
import { Button, Empty } from 'vant';
import iconEmpty from './images/empty.png';
import iconNetwork from './images/network.png';
import icon404 from './images/404.png';
import icon_empty from './images/icon_empty.png';
import icon_list_emtry from './images/icon_list_emtry.png';

export default defineComponent({
  name: 'm-empty',
  props: {
    description: {
      type: String as PropType<string | undefined>,
      default: ''
    },
    image: {
      type: String as PropType<'empty' | 'network' | '404' | 'icon_empty' | 'list'>,
      default: 'icon_empty'
    },
    showButton: {
      type: Boolean,
      default: false
    },
    buttonText: {
      type: String,
      default: '返回'
    }
  },
  emits: ['click'],
  setup(props, { emit }) {
    const forms = reactive({
      image: icon_empty
    });

    onMounted(() => {
      if (props.image === 'network') {
        forms.image = iconNetwork;
      } else if (props.image === '404') {
        forms.image = icon404;
      } else if (props.image === 'list') {
        forms.image = icon_list_emtry;
      }
    });
    return () => (
      <Empty
        style={{
          paddingTop: 0
        }}
        class={styles.mEmpty}
        image={forms.image}
        description={props.description}>
        {props.showButton && (
          <Button
            type="primary"
            plain
            round
            class={styles.button}
            onClick={() => emit('click')}>
            {props.buttonText}
          </Button>
        )}
      </Empty>
    );
  }
});
