"use client";

import { createContext, useContext } from "react";

export type CartUIContextValue = {
  isOpen: boolean;
  openCart: (triggerElement?: HTMLElement | null) => void;
  closeCart: () => void;
};

export const CartUIContext = createContext<CartUIContextValue | null>(null);

export function useCartUI(): CartUIContextValue {
  const ctx = useContext(CartUIContext);
  if (!ctx) {
    throw new Error("useCartUI must be used within CartUIProvider");
  }
  return ctx;
}
