import { RulesStore } from '@/types/app-type'
import { defineStore } from 'pinia'

const initState = {
  rules: [],
}

export const useRulesStore = defineStore(
  'rules',
  () => {
    const store = ref<RulesStore>({ ...initState })

    const setRules = (val: Array<any>) => {
      store.value.rules = val
    }

    const clearRules = () => {
      store.value = { ...initState }
    }
    // 一般没有reset需求，不需要的可以删除
    const reset = () => {
      store.value = { ...initState }
    }

    return {
      store,
      clearRules,
      setRules,

      reset,
    }
  },
  {
    persist: true,
  },
)
