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 { l as ShoppingCart, t as Zap } 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 { l as useNavigate } from "../_libs/@tanstack/react-router+[...].mjs";
import { t as create } from "../_libs/zustand.mjs";
import { t as useCentralProductStore } from "./central-product-store-TS-vQ8-V.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/flash-CkaCI73Q.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
var useCentralSlotStore = create((set) => ({
	slots: [],
	productSlotsMap: {},
	setSlots: (slots) => set({ slots }),
	setProductSlotsMap: (map) => set({ productSlotsMap: map }),
	refetchSlots: null,
	setRefetchSlots: (fn) => set({ refetchSlots: fn })
}));
function FlashDeliveryPage() {
	const navigate = useNavigate();
	const products = useCentralProductStore((s) => s.products);
	const productSlotsMap = useCentralSlotStore((s) => s.productSlotsMap);
	const [selectedQty, setSelectedQty] = (0, import_react.useState)({});
	const addToCart = useAddToCart("flash");
	const flashProducts = products.filter((p) => productSlotsMap[p.id]?.isFlashAvailable && !productSlotsMap[p.id]?.isOutOfStock);
	const handleAddToCart = (product) => {
		const qty = selectedQty[product.id] || 1;
		addToCart.mutate({
			productId: product.id,
			quantity: qty,
			storeId: product.storeId
		}, { onSuccess: () => navigate({ to: "/flash/cart" }) });
	};
	return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AppContainer, { children: [
		/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
			className: "mb-4 flex items-center gap-2",
			children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Zap, { className: "h-6 w-6 text-yellow-500" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, {
				weight: "bold",
				className: "text-xl",
				children: "1 Hr Delivery"
			})]
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
			className: "mb-4 rounded-xl bg-yellow-50 p-3",
			children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, {
				className: "text-sm text-yellow-800",
				children: "Get these products delivered within 1 hour! Only available for select items."
			})
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
			className: "grid grid-cols-2 gap-3",
			children: flashProducts.map((product) => {
				const price = product.discountedPrice ?? product.price;
				const qty = selectedQty[product.id] || 1;
				return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
					className: "rounded-xl border border-gray-100 bg-white p-3 shadow-sm",
					children: [
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
							className: "mb-2 aspect-square w-full overflow-hidden rounded-lg bg-gray-100",
							children: product.images?.[0] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
								src: product.images[0].uri,
								alt: product.name,
								className: "h-full w-full object-cover"
							})
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, {
							weight: "semibold",
							className: "text-sm",
							numberOfLines: 2,
							children: product.name
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(p, {
							weight: "bold",
							className: "text-brand-600",
							children: ["₹", price]
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
							className: "mt-2 flex items-center gap-2",
							children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Quantifier, {
								value: qty,
								setValue: (v) => setSelectedQty((prev) => ({
									...prev,
									[product.id]: v
								}))
							})
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(MyButton, {
							fullWidth: true,
							onClick: () => handleAddToCart(product),
							className: "mt-2 flex items-center justify-center gap-1 bg-brand-500 text-white text-xs",
							disabled: addToCart.isPending,
							children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShoppingCart, { className: "h-3 w-3" }), "Add"]
						})
					]
				}, product.id);
			})
		}),
		flashProducts.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
			className: "py-20 text-center",
			children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(p, {
				className: "text-gray-500",
				children: "No flash delivery products available"
			})
		})
	] });
}
//#endregion
export { FlashDeliveryPage as component };
