<template>
  <cwg-popup v-model:visible="popupState.visible" type="center" :mask-click="false" :show-footers="true" width="400px">
    <view class="popup-content">
      <view class="confirm-title">{{ popupState.title }}</view>
      <view class="confirm-content">{{ popupState.content }}</view>
    </view>
    <template #footer>
      <button v-if="popupState.showCancel" @click="close">{{ popupState.cancelText }}</button>
      <button class="btn btn-secondary btn-shadow waves-effect" @click="handleConfirm">{{ popupState.confirmText }}</button>
    </template>
  </cwg-popup>
</template>

<script setup>
import { watch, ref } from 'vue'
import { usePopup } from '@/hooks/usePopup'

const { popupState, close, handleConfirm } = usePopup()

const popupRef = ref(null)

watch(() => popupState.value.visible, (val) => {
    if (val) {
        popupRef.value?.open()
    } else {
        popupRef.value?.close()
    }
}, { immediate: true })
</script>

<style scoped lang="scss">
  @import "@/uni.scss";

  :deep(.cwg-dialog) {
    width: px2rpx(500);
    background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
    border-radius: px2rpx(16);
    text-align: center;
    box-shadow: 0 px2rpx(10) px2rpx(20) rgba(0, 0, 0, 0.1);
  }

  .confirm-title {
    font-size: px2rpx(24);
    font-weight: 600;
    color: var(--bs-heading-color);
    margin-bottom: px2rpx(30);
  }

  .confirm-content {
    font-size: px2rpx(20);
    color: var(--bs-heading-color);
    margin-bottom: px2rpx(30);
    line-height: 1.5;
    word-break: break-word;
  }
</style>
