import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
import { CheckoutStoreType } from "../types/Types";

export const useCheckoutStore = create<CheckoutStoreType>()(
  persist(
    (set) => ({
      isSelectedAddress: false,
      setIsSelectedAddress: (value) => set({ isSelectedAddress: value }),
      selectedAddressId: null,
      setSelectedAddressId: (value) => set({ selectedAddressId: value }),
      isSelectedPayment: false,
      setIsSelectedPayment: (value) => set({ isSelectedPayment: value }),
      isSelectedShipment: false,
      setIsSelectedShipment: (value) => set({ isSelectedShipment: value }),
      deliveryType: "0",
      setDeliveryType: (value) => set({ deliveryType: value }),
      paymentType: "0",
      setPaymentType: (value) => set({ paymentType: value }),
      tableNumber: 0,
      setTableNumber: (value) => set({ tableNumber: value }),
      carAddress: null,
      setCarAddress: (value) => set({ carAddress: value }),
    }),
    {
      name: "checkout-storage",
      storage: createJSONStorage(() => localStorage),
    }
  )
);
