import { create } from 'zustand'

export const SEARCH_OPTIONS = [
  {
    id: 'all',
    label: '全体',
  },
  {
    id: 'id',
    label: '登録番号',
  },
  {
    id: 'building_name',
    label: '建物名',
  },
  {
    id: 'representative',
    label: '作成者',
  },
  {
    id: 'store',
    label: '販売店名',
  },
  //   {
  //     id: 'store_id',
  //     label: '販売店ID',
  //   },
  {
    id: 'construction_point',
    label: '施工店名',
  },
  //   {
  //     id: 'construction_id',
  //     label: '施工店ID',
  //   },
]

export const SEARCH_OPTIONS_PARTNERS = [
  {
    id: 'all',
    label: '全体',
  },
  {
    id: 'id',
    label: '登録番号',
  },
  {
    id: 'building_name',
    label: '建物名',
  },
  {
    id: 'representative',
    label: '作成者',
  },
]

export type SEARCH_OPTIONS_ENUM = (typeof SEARCH_OPTIONS)[number]['id']
export type SEARCH_OPTIONS_PARTNERS_ENUM = (typeof SEARCH_OPTIONS_PARTNERS)[number]['id']
export type SORT_OPTIONS_ENUM = 'created' | 'updated'

type SurveyFilterState = {
  keyword: string
  searchOption: SEARCH_OPTIONS_ENUM | SEARCH_OPTIONS_PARTNERS_ENUM
  isMySurvey: string | null
  sort: SORT_OPTIONS_ENUM
  offset: number
  setKeyword: (keyword: string) => void
  setSearchOption: (searchOption: SEARCH_OPTIONS_ENUM | SEARCH_OPTIONS_PARTNERS_ENUM) => void
  setIsMySurvey: (isMySurvey: string | null) => void
  setSort: (sort: SORT_OPTIONS_ENUM) => void
  setOffset: (offset: number) => void
  reset: () => void
}

export const useSurveyFilterStore = create<SurveyFilterState>((set) => ({
  keyword: '',
  searchOption: 'all',
  isMySurvey: null,
  sort: 'created',
  offset: 0,
  setKeyword: (keyword: string) => set({ keyword }),
  setSearchOption: (searchOption: SEARCH_OPTIONS_ENUM | SEARCH_OPTIONS_PARTNERS_ENUM) => set({ searchOption }),
  setIsMySurvey: (isMySurvey: string | null) => set({ isMySurvey }),
  setSort: (sort: SORT_OPTIONS_ENUM) => set({ sort }),
  setOffset: (offset: number) => set({ offset }),
  reset: () => set({ keyword: '', searchOption: 'all', isMySurvey: null, sort: 'created', offset: 0 }),
}))
