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 { c as Star, l as ShoppingCart } from "../_libs/lucide-react.mjs";
import { a as p, i as MyButton, l as Quantifier, t as AppContainer } from "./src-u_N1opJl.mjs";
import { n as useAddToCart } from "./cart-query-hooks-Bz8ID9jY.mjs";
import { n as trpc } from "./trpc-client-CQOIB5UU.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 "./home.product._id-B_8DxUhK.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/home.product._id-C2EPG814.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
function ProductDetailPage() {
	const { id } = Route.useParams();
	const productId = Number(id);
	const navigate = useNavigate();
	const [quantity, setQuantity] = (0, import_react.useState)(1);
	const product = useCentralProductStore((s) => s.productsById)[productId];
	const addToCart = useAddToCart("regular");
	const { data: reviews } = trpc.user.product.getProductReviews.useQuery({ productId }, { enabled: !!productId });
	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: [
		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"]
		}),
		reviews?.data && reviews.data.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
			className: "mt-8",
			children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, {
				weight: "bold",
				className: "mb-3 text-lg",
				children: "Reviews"
			}), reviews.data.map((review, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
				className: "mb-3 rounded-lg border border-gray-100 p-3",
				children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
					className: "mb-1 flex items-center gap-1",
					children: Array.from({ length: review.rating || 5 }).map((_, j) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Star, { className: "h-3 w-3 fill-yellow-400 text-yellow-400" }, j))
				}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, {
					className: "text-sm text-gray-600",
					children: review.comment
				})]
			}, i))]
		})
	] });
}
//#endregion
export { ProductDetailPage as component };
