<template>
  <el-popover
    v-bind="$attrs"
    v-model="visible"
    trigger="click"
    :width="width"
  >
  <div class="el-popconfirm">
    <p class="el-popconfirm__main">
    <i
      v-if="!hideIcon"
      :class="icon"
      class="iconFamily PMSiconattention-fill"
      :style="{color: iconColor}"
    ></i>
      {{title}}
    </p>
    <p
      class="text-sub mt-8"
      :class="{'ml-36': !hideIcon}"
    >{{ content }}</p>
    <div class="el-popconfirm__action mt-16">
      <el-button 
        :type="cancelButtonType" 
        @click="cancel"
        size="mini"
      >
        {{cancelButtonText}}
      </el-button>
      <el-button 
        :type="confirmButtonType" 
        @click="confirm"
        size="mini"
      >
        {{confirmButtonText}}
      </el-button>
    </div>
  </div>
  <slot name="reference" slot="reference"></slot>
</el-popover>
</template>

<script>
import ElPopover from 'element-ui/packages/popover';
import ElButton from 'element-ui/packages/button';
import {t} from 'element-ui/src/locale';

export default {
  name: 'ElPopconfirm',
  props: {
    title: {
      type: String
    },
    content: {
      type: String
    },
    confirmButtonText: {
      type: String,
      default: t('el.popconfirm.confirmButtonText')
    },
    cancelButtonText: {
      type: String,
      default: t('el.popconfirm.cancelButtonText')
    },
    confirmButtonType: {
      type: String,
      default: 'primary'
    },
    cancelButtonType: {
      type: String,
      default: ''
    },
    icon: {
      type: String,
      default: 'el-icon-question'
    },
    iconColor: {
      type: String,
      default: '#f90'
    },
    hideIcon: {
      type: Boolean,
      default: false
    },
    width: {
      type: [Number, String]
    }
  },
  components: {
    ElPopover,
    ElButton
  },
  data() {
    return {
      visible: false
    };
  },
  methods: {
    confirm() {
      this.visible = false;
      this.$emit('onConfirm');
    },
    cancel() {
      this.visible = false;
      this.$emit('onCancel');
    }
  }
};
</script>
