import{k as z,e as Q,r as a,j as e,L as f}from"./vendor-react-CVHocMAO.js";import{k as ee,a4 as G,B as g,L as l,bY as te,bZ as se,I as u,o as ae,p as re,q as ne,t as ie,v,bH as le,X as oe,$ as ce,bT as de}from"./index-Daf0Yezg.js";import{u as me}from"./useDocumentTitle-Gqwy-xKG.js";import"./vendor-amplify-BttVyssp.js";import{c as ue}from"./listings-CetYW0FD.js";import{g as he,r as xe,s as pe}from"./claimRequests-Ce-CZHhE.js";import{C as fe}from"./circle-check-CM6pvw8G.js";import{C as ge}from"./clock-3-C-KGgnkD.js";import{L as j}from"./loader-circle-DvugmlQi.js";import{U as ve}from"./upload-ByxIwi2j.js";import"./vendor-radix-ChuwBYq6.js";import"./vendor-motion-CP2nHqR4.js";import"./vendor-maps-BX5dXCaZ.js";import"./listing-Dh6xmhdV.js";const je=[{value:"claim",label:"Claim this listing",description:"Take ownership and manage it from your own host dashboard."},{value:"edit",label:"Fix something",description:"Something here is inaccurate and should be corrected."},{value:"take_down",label:"Take it down",description:"I'd prefer this venue not be listed on PLEC."}];function Re(){const{id:r}=z(),W=Q(),{toast:y}=de(),{user:n}=ee();me("Claim your venue");const[M,O]=a.useState(""),[V,$]=a.useState(null),[D,h]=a.useState(!!n),[b,H]=a.useState("claim"),[o,N]=a.useState(""),[c,w]=a.useState(""),[C,Y]=a.useState(""),[k,A]=a.useState(""),[S,J]=a.useState(""),[P,_]=a.useState(""),[d,T]=a.useState([]),[E,q]=a.useState(!1),[x,L]=a.useState(!1),[p,K]=a.useState(!1);a.useEffect(()=>{if(!n)return;const t=[n.firstName,n.lastName].filter(Boolean).join(" ").trim();N(s=>s||t||n.preferredName||""),w(s=>s||n.email||"")},[n]),a.useEffect(()=>{if(!r)return;let t=!1;return ue(r).then(s=>{var m,R,B,U;if(t)return;const i=((R=(m=s==null?void 0:s.publishedData)==null?void 0:m.basics)==null?void 0:R.title)||((U=(B=s==null?void 0:s.draftData)==null?void 0:B.basics)==null?void 0:U.title)||"";O(i)}).catch(()=>{}),()=>{t=!0}},[r]),a.useEffect(()=>{if(!n||!r){h(!1);return}let t=!1;return h(!0),he(r).then(s=>{t||$(s)}).catch(()=>{}).finally(()=>{t||h(!1)}),()=>{t=!0}},[n,r]);const F=a.useMemo(()=>!!(o.trim()&&c.trim()&&r&&!x),[o,c,r,x]),X=async t=>{if(r){q(!0);try{const s=await xe(r,t.name,t.type),i=await fetch(s.uploadUrl,{method:"PUT",headers:{"Content-Type":t.type},body:t});if(!i.ok)throw new Error(`Upload failed (${i.status})`);T(m=>[...m,{key:s.key,name:t.name}])}catch{y({title:"Couldn't upload that file",description:"Please try a JPG, PNG, or WebP image. You can also describe your proof in the box instead.",variant:"destructive"})}finally{q(!1)}}},Z=async t=>{if(t.preventDefault(),!(!r||!F)){L(!0);try{await pe(r,{intent:b,requesterName:o.trim(),requesterEmail:c.trim(),requesterPhone:C.trim()||void 0,preferredContactMethod:k||void 0,preferredContactTime:S.trim()||void 0,proofText:P.trim()||void 0,proofFileKeys:d.length?d.map(s=>s.key):void 0}),K(!0)}catch{y({title:"Something went wrong",description:"We couldn't submit your request. Please try again in a moment.",variant:"destructive"})}finally{L(!1)}}},I=M||"this venue";return p||V?e.jsx(G,{showFooter:!0,children:e.jsxs("div",{className:"mx-auto max-w-xl px-4 py-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-brand/10 text-brand",children:p?e.jsx(fe,{className:"h-7 w-7"}):e.jsx(ge,{className:"h-7 w-7"})}),e.jsx("h1",{className:"mt-5 text-2xl font-semibold text-gray-900",children:p?"Request received":"You already have a request in progress"}),e.jsxs("p",{className:"mt-3 text-sm leading-relaxed text-gray-700",children:["Thanks — a member of the PLEC team will reach out to verify your connection to ",I,". We never transfer control of a listing without confirming ownership first, so keep an eye on your email."]}),e.jsxs("div",{className:"mt-8 flex justify-center gap-3",children:[e.jsx(g,{asChild:!0,variant:"outline",className:"rounded-full",children:e.jsx(f,{to:r?`/venue/${r}`:"/venues",children:"Back to the venue"})}),e.jsx(g,{asChild:!0,className:"rounded-full",children:e.jsx(f,{to:"/listing-disclosure",children:"How this works"})})]})]})}):e.jsx(G,{showFooter:!0,children:e.jsxs("div",{className:"mx-auto max-w-xl px-4 py-10",children:[e.jsx("button",{onClick:()=>W(-1),className:"text-sm text-muted-foreground hover:text-foreground",children:"↠Back"}),e.jsx("h1",{className:"mt-3 text-2xl font-semibold text-gray-900",children:"Is this your venue?"}),e.jsxs("p",{className:"mt-2 text-sm leading-relaxed text-gray-700",children:["Our team created this listing for ",I,". Tell us what you'd like to do and we'll be in touch to verify your connection to the venue."," ",e.jsx(f,{to:"/listing-disclosure",className:"text-brand underline-offset-2 hover:underline",children:"How PLEC listings work"})]}),D?e.jsxs("div",{className:"mt-10 flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(j,{className:"h-4 w-4 animate-spin"})," Checking for an existing request…"]}):e.jsxs("form",{onSubmit:Z,className:"mt-8 space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:"What would you like to do?"}),e.jsx(te,{value:b,onValueChange:t=>H(t),className:"gap-2",children:je.map(t=>e.jsxs("label",{htmlFor:`intent-${t.value}`,className:"flex cursor-pointer items-start gap-3 rounded-xl border border-border/70 p-3 hover:bg-muted/40",children:[e.jsx(se,{value:t.value,id:`intent-${t.value}`,className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium text-gray-900",children:t.label}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:t.description})]})]},t.value))})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"claim-name",children:"Your name *"}),e.jsx(u,{id:"claim-name",value:o,onChange:t=>N(t.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"claim-email",children:"Email *"}),e.jsx(u,{id:"claim-email",type:"email",value:c,onChange:t=>w(t.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"claim-phone",children:"Phone"}),e.jsx(u,{id:"claim-phone",type:"tel",value:C,onChange:t=>Y(t.target.value),placeholder:"Optional"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:"Preferred contact method"}),e.jsxs(ae,{value:k,onValueChange:t=>A(t),children:[e.jsx(re,{children:e.jsx(ne,{placeholder:"No preference"})}),e.jsxs(ie,{children:[e.jsx(v,{value:"email",children:"Email"}),e.jsx(v,{value:"phone",children:"Phone call"}),e.jsx(v,{value:"sms",children:"Text message"})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"claim-time",children:"Best time to reach you"}),e.jsx(u,{id:"claim-time",value:S,onChange:t=>J(t.target.value),placeholder:"e.g. weekday mornings (optional)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"claim-proof",children:"How are you connected to this venue?"}),e.jsx(le,{id:"claim-proof",value:P,onChange:t=>_(t.target.value),rows:4,placeholder:"Tell us your role (owner, manager…) and anything that helps us verify — a business email domain, license, or website. This speeds things up."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2 rounded-full border border-border/70 px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-muted/40",children:[E?e.jsx(j,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ve,{className:"h-3.5 w-3.5"}),"Attach proof image",e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",disabled:E,onChange:t=>{var i;const s=(i=t.target.files)==null?void 0:i[0];s&&X(s),t.target.value=""}})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Optional · JPG, PNG, or WebP"})]}),d.length>0&&e.jsx("ul",{className:"space-y-1",children:d.map(t=>e.jsxs("li",{className:"flex items-center justify-between rounded-lg bg-muted/40 px-3 py-1.5 text-xs text-gray-700",children:[e.jsx("span",{className:"truncate",children:t.name}),e.jsx("button",{type:"button",onClick:()=>T(s=>s.filter(i=>i.key!==t.key)),className:"ml-2 text-muted-foreground hover:text-foreground","aria-label":"Remove attachment",children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]},t.key))})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-xl bg-muted/30 p-3 text-xs leading-relaxed text-muted-foreground",children:[e.jsx(ce,{className:"mt-0.5 h-4 w-4 shrink-0 text-brand"}),"We verify ownership before changing anything. This protects venue owners — we'll never hand over a listing to someone who can't confirm their connection to the venue."]}),e.jsx(g,{type:"submit",disabled:!F,className:"w-full rounded-full",children:x?e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"mr-2 h-4 w-4 animate-spin"})," Submitting…"]}):"Submit request"})]})]})})}export{Re as default};