const formattedPrice = (price: number) =>  price.toLocaleString("en-IN", {
    style: "currency",
    currency: "INR",
});

const getCartIdentifier = () => {
  // Check logged in user from localStorage
  const userRaw = localStorage.getItem("user");
  const user = userRaw ? JSON.parse(userRaw) : null;

  // If logged in use userId
  if (user?._id) return { user: user._id };

  // If guest generate/reuse guestId
  let guestId = localStorage.getItem("guestId");
  if (!guestId) {
    guestId = crypto.randomUUID();
    localStorage.setItem("guestId", guestId);
  }

  return { guestId };
}

export { formattedPrice, getCartIdentifier }
