import { defineStore } from 'pinia'
import { DICT_DATA } from '@/stores/constant/cacheKey'
import type { DictData, BasicDictData } from '@/stores/interface/index'
import { reactive } from 'vue'

export const useDictData = defineStore(
    'dictData',
    () => {
        const state: DictData = reactive({
            basic: [],
            area: []
            // 其他接口获取的字典，比如区域
        })
        const getBasicData = (code: string, arr?: string[]) => {
            let list = []
            list = state.basic.filter(item => item.code === code)[0]?.children || []
            if (arr) {
                list = list.filter(item => !arr.includes(item.code))
            }
            return list
        }
        return {
            state,
            getBasicData
        }
    },
    {
        persist: {
            key: DICT_DATA
        }
    }
)
