import { jsxs, jsx } from "react/jsx-runtime";
import { useNavigate, Link } from "@tanstack/react-router";
import { useState } from "react";
import { useMutation } from "@tanstack/react-query";
import { s as supabase } from "./client-CJCZGN4z.js";
import { u as useAuth } from "./use-auth-DoD1gvcu.js";
import { B as Button } from "./button-BXrfXN_b.js";
import { L as Label, I as Input } from "./label-BsuFFEVs.js";
import { T as Textarea } from "./textarea-BBisE2jS.js";
import { S as Select, a as SelectTrigger, b as SelectValue, c as SelectContent, d as SelectItem } from "./select-Dn_c42EA.js";
import { S as SiteHeader, a as SiteFooter } from "./SiteFooter-B6xyoPMr.js";
import { toast } from "sonner";
import { C as CATEGORIES } from "./router-CEaBCHfX.js";
import "@supabase/supabase-js";
import "@radix-ui/react-slot";
import "class-variance-authority";
import "clsx";
import "tailwind-merge";
import "@radix-ui/react-label";
import "@radix-ui/react-select";
import "lucide-react";
function SubmitPage() {
  const navigate = useNavigate();
  const {
    user
  } = useAuth();
  const [title, setTitle] = useState("");
  const [body, setBody] = useState("");
  const [location, setLocation] = useState("");
  const [category, setCategory] = useState("opinion");
  const [imageUrl, setImageUrl] = useState("");
  const submit = useMutation({
    mutationFn: async () => {
      const {
        error
      } = await supabase.from("citizen_submissions").insert({
        submitter_id: user.id,
        submitter_name: user.email?.split("@")[0],
        title,
        body,
        location,
        category,
        image_url: imageUrl || null
      });
      if (error) throw error;
    },
    onSuccess: () => {
      toast.success("Submission received — our editors will review.");
      navigate({
        to: "/"
      });
    },
    onError: (e) => toast.error(e.message)
  });
  return /* @__PURE__ */ jsxs("div", { className: "min-h-screen bg-background", children: [
    /* @__PURE__ */ jsx(SiteHeader, {}),
    /* @__PURE__ */ jsxs("main", { className: "container mx-auto px-4 py-12 max-w-2xl", children: [
      /* @__PURE__ */ jsx(Link, { to: "/", className: "text-xs text-muted-foreground", children: "← Back" }),
      /* @__PURE__ */ jsx("h1", { className: "font-serif text-4xl font-black italic mt-2 mb-2", children: "Submit a Story" }),
      /* @__PURE__ */ jsx("p", { className: "text-muted-foreground mb-8", children: "Share news from your community. Our editors review every submission before publishing." }),
      /* @__PURE__ */ jsxs("form", { onSubmit: (e) => {
        e.preventDefault();
        submit.mutate();
      }, className: "space-y-4", children: [
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx(Label, { children: "Headline" }),
          /* @__PURE__ */ jsx(Input, { required: true, value: title, onChange: (e) => setTitle(e.target.value), maxLength: 200 })
        ] }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx(Label, { children: "Category" }),
          /* @__PURE__ */ jsxs(Select, { value: category, onValueChange: setCategory, children: [
            /* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, {}) }),
            /* @__PURE__ */ jsx(SelectContent, { children: CATEGORIES.map((c) => /* @__PURE__ */ jsx(SelectItem, { value: c.slug, children: c.name }, c.slug)) })
          ] })
        ] }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx(Label, { children: "Location" }),
          /* @__PURE__ */ jsx(Input, { value: location, onChange: (e) => setLocation(e.target.value), placeholder: "e.g. Blantyre", maxLength: 120 })
        ] }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx(Label, { children: "Image URL (optional)" }),
          /* @__PURE__ */ jsx(Input, { type: "url", value: imageUrl, onChange: (e) => setImageUrl(e.target.value) })
        ] }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx(Label, { children: "Your story" }),
          /* @__PURE__ */ jsx(Textarea, { required: true, rows: 10, value: body, onChange: (e) => setBody(e.target.value), maxLength: 5e3 })
        ] }),
        /* @__PURE__ */ jsx(Button, { type: "submit", disabled: submit.isPending || !title || !body, children: "Submit for review" })
      ] })
    ] }),
    /* @__PURE__ */ jsx(SiteFooter, {})
  ] });
}
export {
  SubmitPage as component
};
