import { createGlobalState } from '@vueuse/core'
import {ref} from "vue";
import {goodStore} from "@/stores/goods/index.js";
import {authStore} from "@/stores/auth/index.js";

export const liveStore = createGlobalState(() => {
    const {auctionDetail,getAuctionDetail} = goodStore();
    const { token } = authStore()
    const quoteStatus = ref(false)
    const show = ref(false)
    const show1=ref(true)
    const playerId=ref('J_prismPlayer')
    const auctionData=ref({})
    const getSocketData=async ()=>{
        if (!auctionDetail.value.uuid){
            await getAuctionDetail()
        }
        const { ws, messages, onMessage } = useWebSocket()

// 连接
        ws.connect('/api/v1/m/auction/live',{auctionUuid: auctionDetail.value.uuid,token:token.value})

        /*// 发送消息
          ws.send({ type: 'chat', content: 'Hello!' })*/
// 监听消息
        onMessage((data) => {

            auctionData.value = data
        })
    }
    const changeStatus = () => {
        quoteStatus.value = !quoteStatus.value
    }
    return{
        auctionData,
        getSocketData,
        show1,
        playerId,
        show,
        quoteStatus,
        changeStatus
    }
})