import type { settingItem } from '@/types/home'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useSettingStore = defineStore(
  'setting',
  () => {
    const data = ref<settingItem>({
      version: '1.0.0',
      agreement: {
        user_agreement: '',
        privacy_agreement: '',
        about_us_agreement: '',
      },
      upload_setting: {},
      cdn_url: '',
      h5_domain: '',
      sync_delivery: false,
    })

    const update = (newConfig: settingItem) => {
      data.value = newConfig
    }

    return { data, update }
  },
  {
    persist: {
      storage: {
        setItem(key: string, value: any) {
          return uni.setStorageSync(key, value)
        },
        getItem(key: string) {
          return uni.getStorageSync(key)
        },
      },
    },
  },
)
