import { defineStore } from 'pinia'
import { getConfig } from '@/api/app'

interface AppSate {
    config: Record<string, any>
}
export const useAppStore = defineStore({
    id: 'appStore',
    state: (): AppSate => ({
        config: {}
    }),
    getters: {
        getWebsiteConfig: (state) => state.config.website || {},
        getLoginConfig: (state) => state.config.login || {},
    },
    actions: {
        getImageUrl(url: string) {
            return url ? `${this.config.domain}${url}` : ''
        },
        async getConfig() {
            const data = await getConfig()
            this.config = data
			uni.setStorageSync('currency', data.website.currency)
			uni.setStorageSync('currency2', data.website.currency2)
			uni.setStorageSync('precision', data.website.precision)
			uni.setStorageSync('lang', data.website.lang)
			uni.setStorageSync('formatTime', data.website.formatTime)
        }
    }
})
