import { NO_CATEGORY } from "@core/Models/Categories.type";
import { create } from "zustand";

export enum HEADER_MODES {
    LARGE = "large",
    SMALL = "small",
}

export enum HEADER_WIDGETS {
    FIND = "find",
    PUBLIC_FIND = "public-find",
    NONE = "none",
}

interface IHeaderStore {
    notificationsCount: number;
    state: HEADER_MODES;
    activeWidget: HEADER_WIDGETS;
    findText: string;
    publicFindText: string;
    publicFindCategoryId: number;
    publicFindTrigger: boolean;
    setNotificationsCount: (count: number) => void;
    setState: (state: HEADER_MODES) => void;
    setFindText: (text: string) => void;
    setPublicFindText: (text: string) => void;
    setPublicFindCategoryId: (id: number) => void;
    setActiveWidget: (widget: HEADER_WIDGETS) => void;
    setPublicFindTrigger: (trigger: boolean) => void;
    clear: () => void;
}

export type HeaderState = IHeaderStore;

const useHeaderStore = create<HeaderState>()((set) => ({
    notificationsCount: 0,
    state: HEADER_MODES.LARGE,
    activeWidget: HEADER_WIDGETS.PUBLIC_FIND,
    findText: "",
    publicFindText: "",
    publicFindCategoryId: NO_CATEGORY,
    publicFindTrigger: false,
    setNotificationsCount: (count: number) => set(() => ({ notificationsCount: count })),
    setState: (state: HEADER_MODES) => set(() => ({ state: state })),
    setFindText: (text: string) => set(() => ({ findText: text })),
    setPublicFindText: (text: string) => set(() => ({ publicFindText: text })),
    setPublicFindCategoryId: (id: number) => set(() => ({ publicFindCategoryId: id })),
    setActiveWidget: (widget: HEADER_WIDGETS) => set(() => ({ activeWidget: widget })),
    setPublicFindTrigger: (trigger: boolean) => set(() => ({ publicFindTrigger: trigger })),
    clear: () =>
        set(() => ({
            notificationsCount: 0,
            state: HEADER_MODES.LARGE,
            activeWidget: HEADER_WIDGETS.PUBLIC_FIND,
            findText: "",
            publicFindText: "",
            publicFindCategoryId: NO_CATEGORY,
            publicFindTrigger: false,
        })),
}));

export { useHeaderStore };
