import { o as __toESM } from "../_runtime.mjs";
import { h as require_react, m as require_jsx_runtime } from "../_libs/react+tanstack__react-query.mjs";
import { S as ArrowLeft, l as ShoppingCart } from "../_libs/lucide-react.mjs";
import { a as p, i as MyButton, l as Quantifier, s as MyTouchableOpacity, t as AppContainer } from "./src-u_N1opJl.mjs";
import { n as useAddToCart } from "./cart-query-hooks-Bz8ID9jY.mjs";
import { l as useNavigate } from "../_libs/@tanstack/react-router+[...].mjs";
import { t as useCentralProductStore } from "./central-product-store-TS-vQ8-V.mjs";
import { t as Route } from "./stores._storeId.product._productId-D-wjnIdD.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/stores._storeId.product._productId-C9GtcXdb.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
function StoreProductDetailPage() {
	const { productId, storeId } = Route.useParams();
	const pid = Number(productId);
	const navigate = useNavigate();
	const [quantity, setQuantity] = (0, import_react.useState)(1);
	const product = useCentralProductStore((s) => s.productsById)[pid];
	const addToCart = useAddToCart("regular");
	const handleAddToCart = () => {
		if (!product) return;
		addToCart.mutate({
			productId: product.id,
			quantity,
			storeId: product.storeId
		}, { onSuccess: () => navigate({ to: "/cart" }) });
	};
	if (!product) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AppContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, { children: "Product not found" }) });
	const price = product.discountedPrice ?? product.price;
	const imageUrl = product.images?.[0];
	return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AppContainer, { children: [
		/* @__PURE__ */ (0, import_jsx_runtime.jsx)(MyTouchableOpacity, {
			onClick: () => navigate({
				to: "/stores/$storeId",
				params: { storeId }
			}),
			className: "mb-4 flex items-center gap-2",
			children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ArrowLeft, { className: "h-5 w-5" })
		}),
		imageUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
			className: "mb-4 aspect-square w-full overflow-hidden rounded-xl bg-gray-100",
			children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
				src: imageUrl,
				alt: product.name,
				className: "h-full w-full object-cover"
			})
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, {
			weight: "bold",
			className: "mb-1 text-xl",
			children: product.name
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(p, {
			className: "mb-2 text-sm text-gray-500",
			children: [product.unitValue, product.unit]
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
			className: "mb-4 flex items-baseline gap-2",
			children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(p, {
				weight: "bold",
				className: "text-2xl text-brand-600",
				children: ["₹", price]
			}), product.discountedPrice && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(p, {
				className: "text-sm text-gray-400 line-through",
				children: ["₹", product.price]
			})]
		}),
		product.description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, {
			className: "mb-4 text-gray-600",
			children: product.description
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
			className: "mb-6",
			children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Quantifier, {
				value: quantity,
				setValue: setQuantity,
				max: 10
			})
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(MyButton, {
			fullWidth: true,
			onClick: handleAddToCart,
			disabled: addToCart.isPending,
			className: "flex items-center justify-center gap-2 bg-brand-500 text-white",
			children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShoppingCart, { className: "h-4 w-4" }), addToCart.isPending ? "Adding..." : "Add to Cart"]
		})
	] });
}
//#endregion
export { StoreProductDetailPage as component };
