<template>
  <el-popconfirm
    v-if="popconfirm"
    :confirm-button-text="popconfirm.confirmText ? popconfirm.confirmText : '确定'"
    :cancel-button-text="popconfirm.cancelText ? popconfirm.cancelText : '取消'"
    :title="popconfirm.title"
    @confirm="emits('confirm')"
    @cancel="emits('cancel')"
  >
    <template #reference>
      <el-button v-bind="$attrs">{{ text }}</el-button>
    </template>
  </el-popconfirm>
  <el-button v-else v-bind="$attrs">{{ text }}</el-button>
</template>

<script lang="ts" setup>
  interface PopconfirmProps {
    title: string;
    confirmText?: string;
    cancelText?: string;
  }
  defineProps<{
    text: string;
    popconfirm?: PopconfirmProps;
  }>();
  const emits = defineEmits(['confirm', 'cancel']);
</script>

<style lang="scss" scoped>
  .el-button {
    border: none;
    outline: none;
    background-color: transparent;
    color: $primary-color;
    padding: 0;
    &:disabled {
      color: $disabled-color;
      background-color: transparent;
    }
  }
</style>
