1import{u as V,f as I,n as K,r as k,b as q,s as p,j as e,C as f,c as b,B as m,K as Y,N as J,bJ as O,I as d,J as x}from"./index-PtGACUVf.js";import{u as $}from"./UpgradeModalContext-B2WWK_2C.js";import{u as H}from"./useMutation-B6B2ZZTv.js";import{u as Q}from"./useListingLimit-Dhavz1IR.js";import{g as R}from"./slug-utils-CW2Vmkgw.js";import{L as r}from"./label-BGYTmHnu.js";import{T as W}from"./textarea-B113Ozlu.js";import{S as v,a as N,b as C,c as w,d as _}from"./select-BwSQ4ldD.js";import{A as Z,a as G}from"./alert-aNjvcd0z.js";import{S as B}from"./skeleton-DaIvcz7V.js";import{C as X}from"./circle-check-big-sSf7dLsd.js";import{C as ee}from"./circle-alert-zZK6adB6.js";import{C as se}from"./credit-card-DCJoW9Uy.js";import{P as ae}from"./plus-Dy1doKva.js";import{S as ie}from"./shield-check-BAvNURxp.js";import"./DashboardUpgradeModal-DxLEzedF.js";import"./tierConfig-C0rjwayP.js";import"./plan-tiers-D5f6_bvF.js";import"./building-2-DaWZqhwr.js";import"./bot-B7UW_4Ys.js";import"./stripe-link-Brwsa8aw.js";import"./dialog-1knjOMG6.js";import"./index-DU2LHGu_.js";import"./eye-B9hDvAFW.js";import"./gift-BjT7Xgdl.js";import"./index-BdQq_4o_.js";import"./chevron-up-BZ1Up2zp.js";function te(){const{openUpgradeModal:o}=$();return e.jsxs(m,{size:"lg",className:"gap-2",onClick:()=>o(),children:[e.jsx(ie,{className:"h-5 w-5"}),"Claim This Listing"]})}function De(){const o=V(),{user:n}=I(),{canCreateMore:D,totalLimit:u,currentCount:S,isLoading:z}=Q(),{categories:l,isLoading:A}=K(),[a,t]=k.useState({city_id:"",name:"",category:"",subcategory_id:"",description:"",address:"",city:"",state:"",zip_code:"",phone:"",email:"",website:""}),[P,E]=k.useState(null),{data:L=[],isLoading:M}=q({queryKey:["user-accessible-cities",n==null?void 0:n.id],queryFn:async()=>{const{data:s,error:i}=await p.from("cities").select("id, name, state").eq("is_active",!0).order("name");if(i)throw i;return s||[]},enabled:!!(n!=null&&n.id)}),{data:g=[]}=q({queryKey:["subcategories",a.category],queryFn:async()=>{const s=l==null?void 0:l.find(h=>h.slug===a.category);if(!s)return[];const{data:i,error:c}=await p.from("subcategories").select("id, name, slug").eq("category_id",s.id).eq("is_active",!0).order("sort_order");if(c)throw c;return i||[]},enabled:!!a.category&&!!(l!=null&&l.length)}),j=H({mutationFn:async()=>{if(!n)throw new Error("Not authenticated");const s=L.find(y=>y.id===a.city_id),i=R(a.name.trim());let c=i,h=2;for(;;){const{data:y}=await p.from("businesses").select("id").eq("city_id",a.city_id).eq("slug",c).maybeSingle();if(!y)break;c=`${i}-${h}`,h++}const{data:T,error:F}=await p.from("businesses").insert({user_id:n.id,name:a.name.trim(),slug:c,category:a.category,subcategory_id:a.subcategory_id||null,description:a.description.trim()||null,address:a.address.trim()||null,city:(s==null?void 0:s.name)||a.city.trim()||null,city_id:a.city_id,state:(s==null?void 0:s.state)||a.state.trim()||null,zip_code:a.zip_code.trim()||null,phone:a.phone.trim()||null,email:a.email.trim()||null,website:a.website.trim()||null,approved_status:"pending",is_claimed:!1}).select("id, name").single();if(F)throw F;return T},onSuccess:s=>{E({id:s.id,name:s.name})},onError:s=>{x.error("Failed to create listing: "+s.message)}}),U=s=>{if(s.preventDefault(),!a.name.trim()){x.error("Business name is required");return}if(!a.category){x.error("Please select a category");return}if(!a.city_id){x.error("Please select a city");return}j.mutate()};return z||M||A?e.jsxs("div",{className:"space-y-6",children:[e.jsx(B,{className:"h-10 w-64"}),e.jsx(B,{className:"h-96 w-full"})]}):P?e.jsx("div",{className:"space-y-6",children:e.jsx(f,{className:"border-primary/20",children:e.jsxs(b,{className:"py-12 text-center",children:[e.jsx("div",{className:"mx-auto mb-6 w-16 h-16 bg-primary/10 rounded-full flex items-center justify-center",children:e.jsx(X,{className:"h-8 w-8 text-primary"})}),e.jsx("h2",{className:"text-2xl font-display font-bold text-foreground mb-3",children:"Your business has been submitted for review!"}),e.jsx("p",{className:"text-muted-foreground mb-8 max-w-md mx-auto",children:"Once approved, claim your listing to unlock premium features like photos, deals, and contact info."}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-center gap-4",children:[e.jsx(te,{}),e.jsx(m,{variant:"outline",size:"lg",onClick:()=>
1o("/dashboard"),children:"Back to Dashboard"})]})]})})}):D?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-display font-bold flex items-center gap-2",children:[e.jsx(ae,{className:"h-6 w-6"}),"Create New Listing"]}),e.jsxs("p",{className:"text-muted-foreground",children:["Add a new business to the directory (",S+1," of ",u,")"]})]}),e.jsx("form",{onSubmit:U,children:e.jsxs(f,{children:[e.jsxs(Y,{children:[e.jsx(J,{children:"Business Details"}),e.jsx(O,{children:"Enter the basic information for your new listing"})]}),e.jsxs(b,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"city_id",children:"City *"}),e.jsxs(v,{value:a.city_id,onValueChange:s=>t(i=>({...i,city_id:s})),children:[e.jsx(N,{children:e.jsx(C,{placeholder:"Select a city for this listing"})}),e.jsx(w,{children:L.map(s=>e.jsxs(_,{value:s.id,children:[s.name,", ",s.state]},s.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose which city directory this listing will appear in"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"name",children:"Business Name *"}),e.jsx(d,{id:"name",value:a.name,onChange:s=>t(i=>({...i,name:s.target.value})),placeholder:"Enter business name",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"category",children:"Category *"}),e.jsxs(v,{value:a.category,onValueChange:s=>t(i=>({...i,category:s,subcategory_id:""})),children:[e.jsx(N,{children:e.jsx(C,{placeholder:"Select a category"})}),e.jsx(w,{children:l==null?void 0:l.map(s=>e.jsx(_,{value:s.slug,children:s.name},s.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"subcategory",children:"Subcategory"}),e.jsxs(v,{value:a.subcategory_id,onValueChange:s=>t(i=>({...i,subcategory_id:s})),disabled:!a.category||g.length===0,children:[e.jsx(N,{children:e.jsx(C,{placeholder:g.length?"Select a subcategory":"No subcategories"})}),e.jsx(w,{children:g.map(s=>e.jsx(_,{value:s.id,children:s.name},s.id))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"description",children:"Description"}),e.jsx(W,{id:"description",value:a.description,onChange:s=>t(i=>({...i,description:s.target.value})),placeholder:"Describe your business...",rows:4})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"address",children:"Street Address"}),e.jsx(d,{id:"address",value:a.address,onChange:s=>t(i=>({...i,address:s.target.value})),placeholder:"123 Main Street"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"space-y-2 col-span-2 md:col-span-1",children:[e.jsx(r,{htmlFor:"city",children:"City"}),e.jsx(d,{id:"city",value:a.city,onChange:s=>t(i=>({...i,city:s.target.value})),placeholder:"City"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"state",children:"State"}),e.jsx(d,{id:"state",value:a.state,onChange:s=>t(i=>({...i,state:s.target.value})),placeholder:"State"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"zip",children:"ZIP Code"}),e.jsx(d,{id:"zip",value:a.zip_code,onChange:s=>t(i=>({...i,zip_code:s.target.value})),placeholder:"12345"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"phone",children:"Phone"}),e.jsx(d,{id:"phone",type:"tel",value:a.phone,onChange:s=>t(i=>({...i,phone:s.target.value})),placeholder:"(555) 123-4567"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"email",children:"Email"}),e.jsx(d,{id:"email",type:"email",value:a.email,onChange:s=>t(i=>({...i,email:s.target.value})),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"website",children:"Website"}),e.jsx(d,{id:"website",type:"url",value:a.website,onChange:s=>t(i=>({...i,website:s.target.value})),placeholder:"https://www.example.com"})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t",children:[e.jsx(m,{type:"button",variant:"outline",onClick:()=>
1o("/dashboard"),children:"Cancel"}),e.jsx(m,{type:"submit",disabled:j.isPending,children:j.isPending?"Creating...":"Create Listing"})]})]})]})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-display font-bold",children:"Create New Listing"}),e.jsx("p",{className:"text-muted-foreground",children:"Add a new business to the directory"})]}),e.jsxs(Z,{variant:"destructive",children:[e.jsx(ee,{className:"h-4 w-4"}),e.jsxs(G,{children:["You've reached your listing limit (",S," of ",u,"). Upgrade your plan to add more listings."]})]}),e.jsx(f,{children:e.jsxs(b,{className:"py-12 text-center",children:[e.jsx(se,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Upgrade to Add More Listings"}),e.jsxs("p",{className:"text-muted-foreground mb-6 max-w-md mx-auto",children:["Your current plan allows ",u," listing",u!==1?"s":"",". Upgrade to add more businesses to the directory."]}),e.jsx(m,{onClick:()=>o("/dashboard/billing"),children:"View Upgrade Options"})]})})]})}export{De as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.