{"version":3,"file":"popup.vue.mjs","sources":["../../../../../../packages/components/popconfirm/src/popup.vue"],"sourcesContent":["<script lang=\"ts\">\n  import type { StyleValue } from 'vue'\n  import { reactive, computed, defineComponent, onUnmounted, ref } from 'vue'\n  import { getNamespace } from '../../../utils/global-config'\n  import BnSpace from '../../space/src/space.vue'\n  import BnButton from '../../button/src/button.vue'\n  import { addUnit } from '../../../shared/utils'\n  import { BnIconPrompt } from '../../icon'\n  import { isFunction, isPromise } from '../../../utils/is'\n\n  export default defineComponent({\n    name: 'PopconfirmPopup',\n    components: {\n      BnSpace,\n      BnButton,\n      BnIconPrompt\n    },\n    props: {\n      width: {\n        type: [String, Number],\n        default: ''\n      },\n      content: {\n        type: Object,\n        default: () => ({})\n      },\n      okText: {\n        type: String,\n        default: 'String'\n      },\n      cancelText: {\n        type: String,\n        default: ''\n      },\n      popupClass: {\n        type: String,\n        default: undefined\n      },\n      onBeforeCancel: {\n        type: Function,\n        default: undefined\n      },\n      onBeforeOk: {\n        type: Function,\n        default: undefined\n      },\n      type: {\n        type: String,\n        default: undefined\n      }\n    },\n    emits: ['ok', 'cancel', 'close', 'destroy'],\n    setup(props, { emit }) {\n      const ns = getNamespace('popconfirm')\n      const visible = ref(true)\n\n      const popupCls = computed(() => [\n        ns,\n        props.popupClass && props.popupClass,\n        props.type && `is-${props.type}`\n      ])\n\n      const popupStyle = computed(() => {\n        const style: StyleValue = {}\n        style['--bn-trigger-arrow-background-color'] = '#fff'\n        style.width = addUnit(props.width)\n        return style\n      })\n\n      const loadingObj = reactive({\n        ok: false,\n        cancel: false\n      })\n\n      const changeVisible = (value: boolean) => {\n        visible.value = value\n      }\n\n      const handleOk = (e: Event) => {\n        const beforeOk = props.onBeforeOk\n        let ret = true\n        if (isFunction(beforeOk)) {\n          ret = beforeOk()\n          if (isPromise(ret)) {\n            loadingObj.ok = true\n            ret.then((valid) => {\n              loadingObj.ok = false\n              if (valid) {\n                emit('ok', e)\n              }\n            })\n            return\n          }\n        }\n        if (ret) {\n          emit('ok', e)\n        }\n      }\n\n      const handleCancel = (e: Event) => {\n        const beforeCancel = props.onBeforeCancel\n        let ret = true\n        if (isFunction(beforeCancel)) {\n          ret = beforeCancel()\n          if (isPromise(ret)) {\n            loadingObj.cancel = true\n            ret.then((valid) => {\n              loadingObj.cancel = false\n              if (valid) {\n                emit('cancel', e)\n              }\n            })\n            return\n          }\n        }\n        if (ret) {\n          emit('cancel', e)\n        }\n      }\n\n      const beforeLeave = () => {\n        emit('close')\n      }\n\n      const afterLeave = () => {\n        emit('destroy')\n      }\n\n      onUnmounted(() => {\n        visible.value = false\n      })\n\n      return {\n        ns,\n        visible,\n        popupCls,\n        popupStyle,\n        loadingObj,\n        changeVisible,\n        handleOk,\n        handleCancel,\n        beforeLeave,\n        afterLeave\n      }\n    }\n  })\n</script>\n\n<template>\n  <transition\n    name=\"bn-fade-in-standard\"\n    appear\n    @before-leave=\"beforeLeave\"\n    @after-leave=\"afterLeave\"\n  >\n    <div v-show=\"visible\" :class=\"popupCls\" :style=\"popupStyle\">\n      <div :class=\"[`${ns}__content`]\">\n        <slot name=\"content\">\n          <BnIconPrompt :class=\"[`${ns}__icon`]\" :size=\"16\" />\n          <div :class=\"[`${ns}__title`]\">{{ content?.value }}</div>\n        </slot>\n      </div>\n      <div :class=\"[`${ns}__footer`]\">\n        <BnSpace :size=\"12\">\n          <BnButton size=\"small\" :loading=\"loadingObj.cancel\" @click=\"handleCancel\">{{\n            cancelText\n          }}</BnButton>\n          <BnButton size=\"small\" type=\"primary\" :loading=\"loadingObj.ok\" @click=\"handleOk\">{{\n            okText\n          }}</BnButton>\n        </BnSpace>\n      </div>\n      <div class=\"arrow\"></div>\n    </div>\n  </transition>\n</template>\n"],"names":["_resolveComponent","_openBlock","_createBlock","_Transition","_withCtx","_withDirectives","_createElementVNode","popupStyle","_normalizeClass","_normalizeStyle","_renderSlot","ns","_createVNode","content","loadingObj","visible"],"mappings":";;;;;;;6BAqJEA,iBAyBa,SAAA,CAAA,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