import {defineStore} from 'pinia'
import {computed, ref} from 'vue'
// import {dictFineOne} from "@/service";

export const useConfigStore = defineStore(
    'config',
    () => {

        // 显示网络服务
        const showNetworkAnomaly = ref(false)

        // 当前时间
        const serverTime = ref('')

        // 待付款订单取消时间，单位分钟
        const orderCancelTime = ref<string | number>('')
        // 待付款订单取消时间，单位分钟
        const refundOrderAutoAuditTime = ref<string | number>('')
        // 设备 id
        const deviceId = ref('')

        // 运行平台 app | web | mp-weixin
        const uniPlatform = ref('')

        // 系统名称
        const osName = ref('')

        // 系统版本
        const osVersion = ref('')

        // app版本
        const appVersion = ref('')

        // 状态栏高度
        const statusBarHeight = ref(0)

        // 窗口高度
        const windowHeight = ref(0)

        // 窗口宽度
        const windowWidth = ref(0)

        // 屏幕宽度
        const screenWidth = ref(0)

        // 屏幕高度
        const screenHeight = ref(0)

        // tabbar索引
        const tabbarIndex = ref<string | null>(null)

        // 是否显示引导页
        const isShowedGuidePage = ref(false)

        // 是否展示过语言选择页面
        const isShowedLanguageSelectPage = ref(false)

        // 安全距离
        const safeAreaInsets = ref<{
            bottom: number
            top: number
        }>({
            bottom: 0,
            top: 0,
        })
        // 是否是App
        const isApp = computed(() => {
            return uniPlatform.value === 'app'
        })

        // 是否是ios
        const isIos = computed(() => {
            return osName.value === 'ios'
        })

        // 是否是android
        const isAndroid = computed(() => {
            return osName.value === 'android'
        })

        // ios底部安全区占位
        const iosSafeBottomPlaceholder = computed(() => {
            if (isIos.value) {
                return {
                    paddingBottom: safeAreaInsets.value.bottom + 'px',
                }
            }
            return {}
        })

        return {
            showNetworkAnomaly,
            isApp,
            isIos,
            isAndroid,
            appVersion,
            osName,
            osVersion,
            uniPlatform,
            statusBarHeight,
            windowHeight,
            windowWidth,
            screenWidth,
            screenHeight,
            safeAreaInsets,
            deviceId,
            iosSafeBottomPlaceholder,
            serverTime,
            tabbarIndex,
            orderCancelTime,
            refundOrderAutoAuditTime,
            isShowedGuidePage,
            isShowedLanguageSelectPage,
        }
    },
    {
        persist: true,
    },
)
