"use client"; import { create } from "zustand"; import { createJSONStorage, persist } from "zustand/middleware"; // Ciudad de envio elegida desde el header ("Enviar a ... ยท Cali"), mismo // patron persistido que wishlist/cart. Se guardan los ids DIVIPOLA (no // texto libre, ver lib/data/colombia.ts) para que el checkout arranque con // el mismo departamento/ciudad ya seleccionados. interface LocationState { departmentId: number | null; cityId: number | null; hasHydrated: boolean; setHasHydrated: (value: boolean) => void; setLocation: (departmentId: number, cityId: number) => void; } export const useLocationStore = create()( persist( (set) => ({ departmentId: null, cityId: null, hasHydrated: false, setHasHydrated: (value) => set({ hasHydrated: value }), setLocation: (departmentId, cityId) => set({ departmentId, cityId }), }), { name: "ari-shopping-location-v1", storage: createJSONStorage(() => localStorage), partialize: (state) => ({ departmentId: state.departmentId, cityId: state.cityId }), onRehydrateStorage: () => (state) => state?.setHasHydrated(true), }, ), );