<template>
  <pop class="lofty-under-mask-pop" ref="popRef" :on-close="onClose" :allowClose="false">
    <div class="pop-confirm-container">
      <div class="title">
        {{ title }}
        <i v-if="showClose" class="lofty_iconfont lofty-icon-close" @click="close"></i>
      </div>
      <div class="confirm-content">
        <p>{{content}}</p>
      </div>
      <div class="footer">
        <div style="margin-left: auto"></div>
        <div v-if="showCancelButton" class="footer-cancel" @click="close">Cancel</div>
        <div class="footer-confirm" :class="type" @click="confirm">{{ confirmButtonText }}</div>
      </div>
    </div>
  </pop>
</template>


<script setup>
import Pop from './index.vue';
const { title, content, onCancel, onConfirm, onClose, showCancelButton, confirmButtonText, type, showClose } = defineProps( {
  title: String,
  content: String,
  onCancel: Function,
  onConfirm: Function,
  onClose: Function,
  confirmButtonText: {
    type: String,
    default: 'Delete',
  },
  showCancelButton: {
    type: Boolean,
    default: true,
  },
  type: {
    type: String,
    default: 'danger',
  },
  showClose: {
    type: Boolean,
    default: true
  }
})

const popRef = useTemplateRef('popRef')

function close() {
  popRef.value?.close();
  onCancel && onCancel()
}
function confirm() {
  popRef.value?.close();
  onConfirm && onConfirm()
}
onMounted(()=>{
  popRef.value?.open();
})
</script>
<style lang="scss">
.pop-confirm-container {
  width: 500px;
  background: #fff;
  @include media-600 {
    width: 350px;
    margin: 0 auto;
  }
  .title {
    font-size: 16px;
    height: 50px;
    font-family: 'font-bold';
    color: rgba(25, 25, 25, 1);
    border-bottom: rgba(218, 218, 218, 0.5) solid 1px;
    padding-left: 20px;
    padding-top: 16px;
    position: relative;
    .lofty-icon-close {
      position: absolute;
      right: 20px;
      top: 15px;
      cursor: pointer;
    }
  }
  .confirm-content {
    padding: 20px 30px;
    font-size: 14px;
    font-family: 'font-regular';
    line-height: 27px;
  }
  .footer {
    display: flex;
    align-items: center;
    border-top: rgba(218, 218, 218, 0.5) solid 1px;
    padding: 20px 0;
    >div {
      width: 100px;
      height: 40px;
      line-height: 40px;
      text-align: center;
    }
    .footer-cancel {
      color: rgba(168, 168, 168, 1);
      font-size: 14px;
      font-family: 'font-regular';
      cursor: pointer;
    }
    .footer-confirm {
      margin-right: 20px;
      color: #fff;
      font-size: 14px;
      font-family: 'font-regular';
      cursor: pointer;
    }
    .danger {
      background: rgba(240, 69, 76, 1);
    }
    .normal {
      background: #111111;
    }
  }
}
</style>