<template>
    <app-drawer title="提示" v-model:show="show" :loading="loading">
        <div style="font-size:16px;text-align:center">是否收藏该商品？</div>
        <template #footer>
            <el-button @click="onCancel" plain>取消</el-button>
            <el-button type="primary" @click="onSubmit">确认</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { useDiamondFavorite } from '@/business/goods'
import { useFavoriteStore } from '@/stores'
import AppDrawer from '@pc/components/base/drawer/index.vue'

const props = defineProps({
    selectedRow: {
        type: Object as PropType<Ermcp.MyWRPositionRsp | Ermcp.SellOrderRsp>,
        default: () => ({})
    },
})

const { loading, formSubmit } = useDiamondFavorite(props.selectedRow)
const { getFavoriteList } = useFavoriteStore()
const show = shallowRef(true)

const onCancel = () => {
    show.value = false
}

const onSubmit = () => {
    formSubmit(1).then(() => {
        ElMessage.success('提交成功')
        getFavoriteList()
        onCancel()
    }).catch((err) => {
        ElMessage.error('提交失败：' + err)
    })
}
</script>