<template>
    <view class="mask" v-if="visible">
        <view class="dialog">
            <view class="title">{{ dialogInfo.title }}</view>
            <view class="content">
                <rich-text :nodes="dialogInfo.content"></rich-text>
            </view>
            <view class="options">
                <view class="btn cancle" @tap="visible = false">{{ cancelText }}</view>
                <view class="btn confirm" @tap="confirm">{{ confirmText }}</view>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    props: {
        cancelText: {
            type: String,
            default: '取消'
        },
        confirmText: {
            type: String,
            default: '确定'
        }
    },
    data() {
        return {
            visible: false,
            dialogInfo: {
                title: '',
                content: ''
            }
        }
    },
    methods: {
        open(info) {
            this.visible = true
            this.dialogInfo = info
        },
        confirm() {
            this.visible = false
            this.$emit('confirm')
        }
    }
};
</script>

<style scoped lang="scss">
.mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;

    &-enter-active,
    &-leave-active {
        transition: opacity 0.3s ease;
    }

    &-enter,
    &-leave-to {
        opacity: 0;
    }
}

.dialog {
    padding: 48rpx 48rpx 0;
    width: 568rpx;
    min-height: 354rpx;
    background: #FFFFFF;
    border-radius: 40rpx;
    animation: fadeIn 0.3s ease;
    position: relative;
    padding-bottom: 80px;

    .title {
        font-family: PingFangSC, PingFang SC;
        font-weight: bold;
        font-size: 32rpx;
        color: #000;
        text-align: center;
        margin-bottom: 20rpx;
    }

    .content {
        font-weight: 400;
        font-size: 28rpx;
        color: #666666;
        line-height: 38rpx;
    }

    .options {
        background: #fff;
        border-bottom-left-radius: 40rpx;
        border-bottom-right-radius: 40rpx;
        position: absolute;
        bottom: 0;
        left: 0;
        z-index: 10;
        width: 100%;
        display: flex;
        justify-content: space-between;
        border-top: 2rpx solid #EAEAEA;

        &::after {
            content: "";
            position: absolute;
            left: 50%;
            top: 0;
            height: 100%;
            width: 2rpx;
            background: #EAEAEA;
        }

        .btn {
            flex: 1;
            text-align: center;
            padding: 32rpx 0;
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 32rpx;
            &:active {
                background: #EAEAEA;
            }
            &.cancle {
                border-bottom-left-radius: 40rpx;
                color: #191D23;
            }
            
            &.confirm {
                border-bottom-right-radius: 40rpx;
                color: #0A59F7;
            }
        }
    }
}

@keyframes fadeIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}
</style>