import type {
  activeSearchChartSchema,
  activeSearchListSchema,
  Domain,
  helpActiveSchema,
  helpSchema,
  searchActiveTab,
  searchChartActiveTab,
  searchListActiveTab,
  searchSchema,
  searchSynonymForm,
  searchSynonymTitle,
  selectionFilterItems,
} from "~/types/searchTypes";

import type {
  isReturnFromItemshowPage,
  list,
  listComponentName,
  listId,
  projects,
  selectedItem,
  selectedProject,
} from "~/types/listTypes";

export const useHadithaStore = defineStore("hadithaStore", {
  persist: {
    storage: piniaPluginPersistedstate.localStorage(),
  },  state: () => ({
    selectedProject: undefined as selectedProject | undefined,
    isReturnFromItemshowPage: false as isReturnFromItemshowPage,
    list: undefined as list | undefined,
    listId: undefined as listId | undefined,
    listComponentName: "ItemList" as listComponentName | undefined,
    projects: [] as projects[],
    // pieData: [],
    selectedItem: undefined as selectedItem | undefined,


    domainActive: undefined as Domain | undefined,
    // activeTab: undefined,

    searchActiveTab: undefined as searchActiveTab | undefined,
    searchSchema: undefined as searchSchema | undefined,
    helpSchema: undefined as helpSchema | undefined,
    searchActiveSchema: undefined as searchActiveTab | undefined,
    helpActiveSchema: undefined as helpActiveSchema | undefined,

    searchListActiveTab: undefined as searchListActiveTab | undefined,
    searchListSchema: undefined as searchListActiveTab[] | undefined,
    activeSearchListSchema: undefined as activeSearchListSchema | undefined,

    searchChartActiveTab: undefined as searchChartActiveTab | undefined,
    searchChartSchema: undefined as searchChartActiveTab[] | undefined,
    activeSearchChartSchema: undefined as activeSearchChartSchema | undefined,

    searchSynonymTitle: undefined as searchSynonymTitle | undefined,
    searchSynonymForm: undefined as searchSynonymForm | undefined,

    selectionFilterItems: [] as selectionFilterItems,
  }),
  getters: {
    projectsGetter(state) {
      return state.projects;
    },
    selectedProjectGetter(state) {
      return state.selectedProject;
    },
    listIdGetter(state) {
      return state.listId;
    },
    listComponentNameGetter(state) {
      return state.listComponentName;
    },
    selectedItemGetter(state) {
      return state.selectedItem;
    },
    isReturnFromItemshowPageGetter(state) {
      return state.isReturnFromItemshowPage;
    },
    listGetter(state) {
      return state.list;
    },

    searchSynonymTitleGetter(state) {
      return state.searchSynonymTitle;
    },
    searchSynonymFormGetter(state) {
      return state.searchSynonymForm;
    },

    domainActiveGetter(state) {
      return state.domainActive;
    },
    // activeTabGetter(state) {
    //   return state.activeTab;
    // },

    // search page
    searchActiveTabGetter(state) {
      return state.searchActiveTab;
    },
    searchSchemaGetter(state) {
      return state.searchSchema;
    },
    helpSchemaGetter(state) {
      return state.helpSchema;
    },
    helpActiveSchemaGetter(state) {
      return state.helpActiveSchema;
    },
    searchActiveSchemaGetter(state) {
      return state.searchActiveSchema;
    },

    // search list
    searchListActiveTabGetter(state) {
      return state.searchListActiveTab;
    },
    searchListSchemaGetter(state) {
      return state.searchListSchema;
    },
    searchListActiveSchemaGetter(state) {
      return state.activeSearchListSchema;
    },

    // search chart
    searchChartActiveTabGetter(state) {
      return state.searchChartActiveTab;
    },
    searchChartSchemaGetter(state) {
      return state.searchChartSchema;
    },
    searchChartActiveSchemaGetter(state) {
      return state.activeSearchChartSchema;
    },
    selectionFilterItemsGetter(state) {
      return state.selectionFilterItems;
    },
  },
  actions: {
    SET_SELECTED_PROJECT(selectedProject = undefined) {
      this.selectedProject = selectedProject;
    },
    SET_LIST_ID(listId = undefined) {
      this.listId = listId;
    },
    SET_LIST_COMPONENT_NAME(
      payload = { selectedItem: undefined, listComponentName: undefined }
    ) {
      this.selectedItem = payload.selectedItem;
      this.listComponentName = payload.listComponentName;
    },
    SET_SELECTED_ITEM(selectedItem = undefined) {
      this.selectedItem = selectedItem;
    },
    SET_IS_RETURN_FROM_ITEM_SHOW_PAGE(isReturnFromItemshowPage = false) {
      this.isReturnFromItemshowPage = isReturnFromItemshowPage;
    },
    SET_LIST(list = undefined) {
      this.list = list;
    },
    
    searchSynonymFormSetter(searchSynonymForm = undefined) {
      this.searchSynonymForm = searchSynonymForm;
    },
    searchSynonymTitleSetter(searchSynonymTitle = undefined) {
      this.searchSynonymTitle = searchSynonymTitle;
    },

    domainActiveSetter(domain = undefined) {
      this.domainActive = domain;
    },
    // activeTabSetter(activeTab = undefined) {
    //   this.activeTab = activeTab;
    // },

    // search page
    searchActiveTabSetter(searchActiveTab: searchActiveTab = undefined) {
      this.searchActiveTab = searchActiveTab;
    },
    searchSchemaSetter(searchSchema = undefined) {
      this.searchSchema = searchSchema;
    },
    helpSchemaSetter(helpSchema = undefined) {
      this.helpSchema = helpSchema;
    },
    helpActiveSchemaSetter(helpActiveSchema = undefined) {
      this.helpActiveSchema = helpActiveSchema;
    },
    searchActiveSchemaSetter(searchActiveSchema = undefined) {
      this.searchActiveSchema = searchActiveSchema;
    },

    // search list
    searchListActiveTabSetter(searchListActiveTab = undefined) {
      this.searchListActiveTab = searchListActiveTab;
    },
    searchListSchemaSetter(searchListSchema = undefined) {
      this.searchListSchema = searchListSchema;
    },
    searchListActiveSchemaSetter(activeSearchListSchema = undefined) {
      this.activeSearchListSchema = activeSearchListSchema;
    },

    // search chart
    searchChartActiveTabSetter(searchChartActiveTab = undefined) {
      this.searchChartActiveTab = searchChartActiveTab;
    },
    searchChartSchemaSetter(searchChartSchema = undefined) {
      this.searchChartSchema = searchChartSchema;
    },
    searchChartActiveSchemaSetter(activeSearchChartSchema = undefined) {
      this.activeSearchChartSchema = activeSearchChartSchema;
    },
    selectionFilterItemsSetter(selectionFilterItems = []) {
      this.selectionFilterItems = <selectionFilterItems>selectionFilterItems;
    },
  },
});
// export default {
//   namespaced:true,

//   state,
//   actions,
//   mutations,
//   getters
// };
