import { defineStore } from 'pinia';
import { getApp, useApp } from '/@/hooks/userApp';


interface AppState {
    panoId: Nullable<string>,
    mode: string,
    flying: boolean,
    floorId: Nullable<string>,
    player: {
        lang: string,
        showVR: boolean,
        showMore: boolean,
        showDescription: boolean,
        showToolbar: boolean,
        showMap: boolean,
        showShare: boolean,
        showUserGuide: boolean,
        showWidgets: boolean,
    },
    router: any,
    controlsBottom: string,
    shoppingguide: boolean
}

export const useAppStore = defineStore({
    id: 'app',
    state: (): AppState => ({
        panoId: null,
        mode: 'panorama',
        flying: false,
        floorId: null,
        player: {
            lang: 'zh',
            showVR: false,
            showMore: false,
            showDescription: false,
            showToolbar: true,
            showMap: true,
            showShare: false,
            showUserGuide: false,
            showWidgets: true,
        },
        router: {},
        controlsBottom: '20px',
        shoppingguide: false

    }),
    getters: {


    },
    actions: {
        showShoppingguide(payload: boolean): void {
            this.shoppingguide = payload
        },
        setMode(payload: string): void {
            console.log('setMode', payload)
            if (payload == this.mode) {
                return
            }
            this.flying = true
            useApp().then(sdk => {
                sdk.Camera[payload]()
                    .then(() => {
                        this.flying = false
                    })
                    .catch(() => {
                        this.flying = false
                    })
            })

            if (payload == 'dollhouse') {
                this.setFloor('all');
            }
            this.mode = payload
        },
        setFloorId(id: string): void {
            this.floorId = id
        },
        setFlying(payload: boolean): void {
            this.flying = payload
        },
        setFloor(id: string): void {
            this.floorId = id
            getApp().Scene.gotoFloor(id)
        },
        showVR(): void {
            this.player.showVR = !this.player.showVR
            this.player.showWidgets = !this.player.showWidgets
            getApp().Camera.vr()
        },
        showUserGuide(payload: boolean): void {
            this.player.showUserGuide = payload
        },
        setControlsBottom(payload: string): void {
            this.controlsBottom = payload
        },
        setPanoId(id: string) {
            this.panoId = id
        },
    }

})