<template>
    <ui-dialog>
        <template #header>
            <span>{{ title }}</span>
            <i class="iconfont icon-close" @click="close('no')" />
        </template>
        <template v-if="$slots.content">
            <slot name="content" />
        </template>
        <template v-else>
            <div class="message" v-html="content" />
        </template>
        <template v-if="!hideFoot" #footer>
            <ui-button v-if="!single" type="cancel" @click="close('no')">{{ noText }}</ui-button>
            <ui-button type="primary" @click="close('ok')">{{ okText }}</ui-button>
        </template>
    </ui-dialog>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { isFunction, omit } from '@kankan/utils'

export default defineComponent({
    name: 'UIConfirm',
    props: {
        title: {
            type: String,
            default: '提示',
        },
        okText: {
            type: String,
            default: '确定',
        },
        noText: {
            type: String,
            default: '取消',
        },
        single: {
            type: Boolean,
            default: false,
        },
        hideFoot: {
            type: Boolean,
            default: false,
        },
        func: Function,
        content: String,
        destroy: Function,
    },
    setup(props, _) {
        const close = result => {
            if (isFunction(props.func) && props.func(result) === false) {
                return
            }
            isFunction(props.destroy) && props.destroy()
        }
        return {
            ...omit(props, 'destroy', 'func'),
            close,
        }
    },
})
</script>
