import { n as __toESM } from "./_runtime.mjs";
import { u as require_react } from "./_libs/@floating-ui/react-dom+[...].mjs";
import { p as require_jsx_runtime } from "./_libs/@radix-ui/react-checkbox+[...].mjs";
import { f as useStore, s as fmt } from "./_ssr/categories-MJJjwt1u.mjs";
import { h as Link } from "./_libs/@tanstack/react-router+[...].mjs";
import { t as Route } from "./_storeSlug-CfTiHJfP.mjs";
import { n as toast } from "./_libs/sonner.mjs";
import { A as MapPin, d as Store, g as ShoppingCart, j as Mail, z as ExternalLink } from "./_libs/lucide-react.mjs";
import { l as Header, n as CheckoutFlow, t as CartDrawer, u as SignInModal } from "./_ssr/Modals-PUPoXlMv.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/_storeSlug-2XeAAj8x.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
function VendorStorefrontPage() {
	const { storeSlug } = Route.useParams();
	const [signInOpen, setSignInOpen] = (0, import_react.useState)(false);
	const [cartOpen, setCartOpen] = (0, import_react.useState)(false);
	const [checkoutOpen, setCheckoutOpen] = (0, import_react.useState)(false);
	const { vendors, getAllProducts } = useStore();
	const vendor = vendors.find((v) => v.storeSlug === storeSlug && v.status === "approved");
	const products = vendor ? getAllProducts().filter((p) => p.vendorEmail === vendor.contactEmail) : [];
	return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
		className: "min-h-screen bg-neutral-50 flex flex-col",
		children: [
			/* @__PURE__ */ (0, import_jsx_runtime.jsx)(SignInModal, {
				open: signInOpen,
				onOpenChange: setSignInOpen
			}),
			/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CartDrawer, {
				open: cartOpen,
				onOpenChange: setCartOpen,
				onCheckout: () => {
					setCartOpen(false);
					setCheckoutOpen(true);
				}
			}),
			/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckoutFlow, {
				open: checkoutOpen,
				onOpenChange: setCheckoutOpen
			}),
			/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Header, {
				onOpenCart: () => setCartOpen(true),
				onOpenSignIn: () => setSignInOpen(true)
			}),
			/* @__PURE__ */ (0, import_jsx_runtime.jsx)("main", {
				className: "flex-1 max-w-[1200px] w-full mx-auto px-4 py-8 flex flex-col gap-8",
				children: !vendor ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
					className: "flex-1 flex flex-col items-center justify-center text-center py-20",
					children: [
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Store, { className: "w-16 h-16 text-neutral-300 mb-4" }),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
							className: "text-3xl font-bold mb-2",
							children: "Store Not Found"
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
							className: "text-neutral-500 mb-6",
							children: "The store you are looking for does not exist or is pending approval."
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
							to: "/",
							className: "text-orange-500 font-medium hover:underline",
							children: "Return to Marketplace"
						})
					]
				}) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
					className: "bg-white rounded-xl border overflow-hidden",
					children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
						className: "h-32 sm:h-48 bg-gradient-to-r from-orange-400 to-orange-600 bg-cover bg-center",
						style: vendor.banner ? { backgroundImage: `url(${vendor.banner})` } : {}
					}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
						className: "px-6 pb-6 sm:px-10 relative",
						children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
							className: "w-24 h-24 sm:w-32 sm:h-32 bg-white rounded-xl border-4 border-white shadow-sm flex items-center justify-center -mt-12 sm:-mt-16 mb-4 bg-orange-50 overflow-hidden",
							children: vendor.logo ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
								src: vendor.logo,
								alt: vendor.businessName,
								className: "w-full h-full object-cover"
							}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
								className: "text-3xl sm:text-5xl font-black text-orange-500",
								children: vendor.businessName.charAt(0)
							})
						}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
							className: "flex flex-col sm:flex-row sm:items-end justify-between gap-4",
							children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
								className: "text-3xl font-bold",
								children: vendor.businessName
							}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
								className: "text-sm text-neutral-500 mt-1 flex items-center gap-2",
								children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Store, { className: "w-4 h-4" }), " Official SulejaMarket Vendor"]
							})] })
						})]
					})]
				}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
					className: "flex flex-col md:flex-row gap-8",
					children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
						className: "w-full md:w-64 flex-shrink-0 space-y-6",
						children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
							className: "bg-white rounded-xl border p-5 space-y-4",
							children: [
								/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
									className: "font-bold border-b pb-2",
									children: "About Store"
								}),
								vendor.businessType && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
									className: "text-sm text-neutral-600",
									children: vendor.businessType
								}),
								vendor.city && vendor.state && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
									className: "flex items-start gap-2 text-sm text-neutral-600",
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(MapPin, { className: "w-4 h-4 text-neutral-400 mt-0.5 shrink-0" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
										vendor.address ? `${vendor.address}, ` : "",
										vendor.city,
										", ",
										vendor.state
									] })]
								}),
								vendor.contactEmail && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
									className: "flex items-start gap-2 text-sm text-neutral-600 break-all",
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mail, { className: "w-4 h-4 text-neutral-400 mt-0.5 shrink-0" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: vendor.contactEmail })]
								}),
								vendor.contactPhone && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
									className: "flex items-start gap-2 text-sm text-neutral-600 break-all",
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
										xmlns: "http://www.w3.org/2000/svg",
										width: "16",
										height: "16",
										viewBox: "0 0 24 24",
										fill: "none",
										stroke: "currentColor",
										strokeWidth: "2",
										strokeLinecap: "round",
										strokeLinejoin: "round",
										className: "w-4 h-4 text-neutral-400 mt-0.5 shrink-0",
										children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z" })
									}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
										vendor.contactPhone,
										" ",
										vendor.altPhone ? ` / ${vendor.altPhone}` : ""
									] })]
								}),
								vendor.rcNumber && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
									className: "flex items-start gap-2 text-sm text-neutral-600 break-all",
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Store, { className: "w-4 h-4 text-neutral-400 mt-0.5 shrink-0" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: ["RC/BN: ", vendor.rcNumber] })]
								}),
								vendor.website && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
									className: "flex items-start gap-2 text-sm text-neutral-600 break-all",
									children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ExternalLink, { className: "w-4 h-4 text-neutral-400 mt-0.5 shrink-0" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
										href: vendor.website.startsWith("http") ? vendor.website : `https://${vendor.website}`,
										target: "_blank",
										rel: "noreferrer",
										className: "text-orange-500 hover:underline",
										children: "Website / Social"
									})]
								})
							]
						})
					}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
						className: "flex-1",
						children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
							className: "flex items-center justify-between mb-6",
							children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h2", {
								className: "text-xl font-bold flex items-center gap-2",
								children: ["Products ", /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
									className: "text-sm font-normal text-neutral-500",
									children: [
										"(",
										products.length,
										")"
									]
								})]
							})
						}), products.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
							className: "bg-white border border-dashed rounded-xl p-12 text-center text-neutral-500",
							children: "This store doesn't have any products listed yet."
						}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
							className: "grid grid-cols-2 md:grid-cols-3 xl:grid-cols-4 gap-4",
							children: products.map((p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProductCard, { p }, p.id))
						})]
					})]
				})] })
			})
		]
	});
}
function ProductCard({ p }) {
	const { addToCart } = useStore();
	return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
		className: "bg-white rounded-lg border overflow-hidden hover:shadow-md transition group flex flex-col h-full",
		children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
			to: "/product/$id",
			params: { id: p.id },
			className: "block aspect-square overflow-hidden relative bg-neutral-100",
			children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
				src: p.images?.[0] || `https://picsum.photos/seed/${p.seed}/400/400`,
				alt: p.name,
				className: "w-full h-full object-cover group-hover:scale-105 transition duration-500"
			}), p.disc && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
				className: "absolute top-2 left-2 bg-orange-500 text-white text-[10px] font-bold px-2 py-1 rounded",
				children: p.disc
			})]
		}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
			className: "p-3 flex flex-col flex-1",
			children: [
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
					className: "text-[10px] text-neutral-400 uppercase tracking-wider mb-1",
					children: p.category
				}),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
					to: "/product/$id",
					params: { id: p.id },
					className: "font-medium text-sm leading-tight hover:text-orange-600 line-clamp-2 mb-2 flex-1",
					children: p.name
				}),
				/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
					className: "flex items-center justify-between mt-auto pt-2",
					children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
						className: "font-bold text-sm",
						children: ["₦ ", fmt(p.price)]
					}), p.old && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
						className: "text-xs text-neutral-400 line-through",
						children: ["₦ ", fmt(p.old)]
					})] }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
						onClick: () => {
							addToCart({
								id: p.id,
								name: p.name,
								price: p.price,
								seed: p.seed
							});
							toast.success("Added to cart");
						},
						className: "w-8 h-8 rounded-full bg-neutral-100 flex items-center justify-center text-neutral-600 hover:bg-orange-50 hover:text-orange-600 transition",
						children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShoppingCart, { className: "w-4 h-4" })
					})]
				})
			]
		})]
	});
}
//#endregion
export { VendorStorefrontPage as component };
