import { r as __toESM } from "../_runtime.mjs";
import { a as require_react, i as require_jsx_runtime, t as useQuery } from "../_libs/react+tanstack__react-query.mjs";
import { h as Link } from "../_libs/@tanstack/react-router+[...].mjs";
import { i as SiteLayout, t as PageBody } from "./Layout-mJm59hV1.mjs";
import { t as supabase } from "./client-TD7udZC7.mjs";
import { r as fetchJobBySlug } from "./jobs-DK-Pa4Ss.mjs";
import { n as toast } from "../_libs/sonner.mjs";
import { t as Route } from "./careers._slug-Ddw1yGjH.mjs";
import { n as stringType, t as objectType } from "../_libs/zod.mjs";
//#region node_modules/.nitro/vite/services/ssr/assets/careers._slug-g_DKlt17.js
var import_react = /* @__PURE__ */ __toESM(require_react());
var import_jsx_runtime = require_jsx_runtime();
var applicationSchema = objectType({
	full_name: stringType().trim().min(1, "Please enter your name").max(120),
	email: stringType().trim().email("Please enter a valid email address").max(255),
	phone: stringType().trim().max(40).optional(),
	cover_letter: stringType().trim().min(20, "Tell us a little more (at least 20 characters)").max(4e3)
});
var RESUME_TYPES = [
	"application/pdf",
	"application/msword",
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
];
var MAX_RESUME_BYTES = 10485760;
var Block = ({ title, body }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
	className: "mt-8",
	children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
		className: "font-display text-2xl text-maroon",
		children: title
	}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
		className: "mt-2 space-y-2 text-[17px] leading-relaxed text-foreground/90",
		children: body.split("\n").filter(Boolean).map((line, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: line.replace(/^[-•]\s*/, "• ") }, i))
	})]
});
function Page() {
	const { slug } = Route.useParams();
	const { data: job, isPending } = useQuery({
		queryKey: ["job", slug],
		queryFn: () => fetchJobBySlug(slug)
	});
	const [submitting, setSubmitting] = (0, import_react.useState)(false);
	const [done, setDone] = (0, import_react.useState)(false);
	async function onSubmit(e) {
		e.preventDefault();
		if (!job) return;
		const fd = new FormData(e.currentTarget);
		const parsed = applicationSchema.safeParse({
			full_name: fd.get("full_name"),
			email: fd.get("email"),
			phone: fd.get("phone"),
			cover_letter: fd.get("cover_letter")
		});
		if (!parsed.success) {
			toast.error(parsed.error.issues[0]?.message ?? "Please check the form");
			return;
		}
		const file = fd.get("resume");
		if (!(file instanceof File) || file.size === 0) {
			toast.error("Please attach your résumé (PDF or Word document).");
			return;
		}
		const ext = (file.name.split(".").pop() ?? "").toLowerCase();
		if (!RESUME_TYPES.includes(file.type) && ![
			"pdf",
			"doc",
			"docx"
		].includes(ext)) {
			toast.error("Résumé must be a PDF or Word document.");
			return;
		}
		if (file.size > MAX_RESUME_BYTES) {
			toast.error("Résumé must be smaller than 10 MB.");
			return;
		}
		setSubmitting(true);
		const path = `${job.slug}/${Date.now()}-${crypto.randomUUID()}.${ext || "pdf"}`;
		if ((await supabase.storage.from("resumes").upload(path, file, {
			contentType: file.type || "application/octet-stream",
			upsert: false
		})).error) {
			setSubmitting(false);
			toast.error("We couldn't upload your résumé. Please try again.");
			return;
		}
		const { error } = await supabase.from("job_applications").insert({
			job_id: job.id,
			full_name: parsed.data.full_name,
			email: parsed.data.email,
			phone: parsed.data.phone || null,
			cover_letter: parsed.data.cover_letter,
			resume_path: path,
			resume_url: null
		});
		setSubmitting(false);
		if (error) {
			toast.error("We couldn't send your application. Please try again.");
			return;
		}
		setDone(true);
		toast.success("Application received — thank you!");
	}
	if (isPending) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SiteLayout, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageBody, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
		className: "text-muted-foreground",
		children: "Loading…"
	}) }) });
	if (!job || !job.is_published) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SiteLayout, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PageBody, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
		className: "font-display text-4xl text-maroon",
		children: "This opening is no longer listed"
	}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
		className: "mt-4",
		children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
			to: "/careers",
			className: "text-maroon underline",
			children: "See all current openings"
		})
	})] }) });
	return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SiteLayout, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(PageBody, { children: [
		/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("nav", {
			className: "mb-4 text-sm text-muted-foreground",
			children: [
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
					to: "/",
					className: "hover:text-maroon",
					children: "Home"
				}),
				" ",
				"/",
				" ",
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
					to: "/careers",
					className: "hover:text-maroon",
					children: "Careers"
				}),
				" ",
				"/ ",
				job.title
			]
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", {
			className: "font-display text-4xl text-maroon",
			children: job.title
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
			className: "mt-2 text-sm uppercase tracking-wide text-gold-dark",
			children: [
				job.department,
				" · ",
				job.location,
				" · ",
				job.employment_type,
				job.salary_range ? ` · ${job.salary_range}` : ""
			]
		}),
		/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
			className: "mt-8 grid gap-12 lg:grid-cols-[1fr_400px]",
			children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
					className: "text-[18px] leading-relaxed text-foreground/90",
					children: job.summary
				}),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Block, {
					title: "About the role",
					body: job.description
				}),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Block, {
					title: "What we're looking for",
					body: job.requirements
				}),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Block, {
					title: "Benefits",
					body: job.benefits
				}),
				/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Block, {
					title: "How to apply",
					body: job.how_to_apply
				})
			] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("aside", {
				className: "h-fit border border-border bg-card p-6 shadow-sm",
				children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
					className: "font-display text-2xl text-maroon",
					children: "Apply for this role"
				}), done ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
					className: "mt-4 text-[17px] leading-relaxed",
					children: "Thank you — your application has been received. We read every one and will be in touch if there is a fit."
				}) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
					onSubmit,
					className: "mt-4 space-y-4",
					children: [
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
							label: "Full name",
							name: "full_name",
							required: true
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
							label: "Email",
							name: "email",
							type: "email",
							required: true
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Field, {
							label: "Phone (optional)",
							name: "phone"
						}),
						/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
							/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
								htmlFor: "resume",
								className: "block text-sm font-semibold text-maroon",
								children: "Résumé (PDF or Word, required)"
							}),
							/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
								id: "resume",
								name: "resume",
								type: "file",
								required: true,
								accept: ".pdf,.doc,.docx,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
								className: "mt-1 w-full border border-input bg-background px-3 py-2 text-[15px] outline-none file:mr-3 file:border-0 file:bg-maroon file:px-3 file:py-1.5 file:text-xs file:uppercase file:text-primary-foreground focus:border-gold"
							}),
							/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
								className: "mt-1 text-xs text-muted-foreground",
								children: "Max 10 MB. Your file is private to our hiring team."
							})
						] }),
						/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
							htmlFor: "cover_letter",
							className: "block text-sm font-semibold text-maroon",
							children: "Why this role?"
						}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", {
							id: "cover_letter",
							name: "cover_letter",
							rows: 6,
							required: true,
							maxLength: 4e3,
							className: "mt-1 w-full border border-input bg-background px-3 py-2 text-[15px] outline-none focus:border-gold"
						})] }),
						/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
							type: "submit",
							disabled: submitting,
							className: "w-full bg-maroon px-5 py-3 uppercase tracking-wide text-primary-foreground hover:bg-maroon-dark disabled:opacity-60",
							children: submitting ? "Sending…" : "Submit application"
						})
					]
				})]
			})]
		})
	] }) });
}
function Field({ label, name, type = "text", required, placeholder }) {
	return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
		htmlFor: name,
		className: "block text-sm font-semibold text-maroon",
		children: label
	}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
		id: name,
		name,
		type,
		required,
		placeholder,
		maxLength: 255,
		className: "mt-1 w-full border border-input bg-background px-3 py-2 text-[15px] outline-none focus:border-gold"
	})] });
}
//#endregion
export { Page as component };
