"use client";

import { create } from "zustand";
import { persist } from "zustand/middleware";
type MarketingDateRange = "7d" | "30d" | "qtd";
type MarketingLocationFilter = "all" | string;

type MarketingUIStore = {
  locationId: MarketingLocationFilter;
  dateRange: MarketingDateRange;
  metaConnected: boolean;
  setLocationId: (locationId: MarketingLocationFilter) => void;
  setDateRange: (dateRange: MarketingDateRange) => void;
  setMetaConnected: (metaConnected: boolean) => void;
};

export const useMarketingUIStore = create<MarketingUIStore>()(
  persist(
    (set) => ({
      locationId: "all",
      dateRange: "30d",
      metaConnected: false,
      setLocationId: (locationId) => set({ locationId }),
      setDateRange: (dateRange) => set({ dateRange }),
      setMetaConnected: (metaConnected) => set({ metaConnected }),
    }),
    {
      name: "casa-benell-marketing-ui",
      partialize: (state) => ({
        locationId: state.locationId,
        dateRange: state.dateRange,
        metaConnected: state.metaConnected,
      }),
    }
  )
);

export type { MarketingDateRange, MarketingLocationFilter };
