1import{j as e}from"./vendor-ui-CEGjIuqP.js";import{h as we,f as Ne,r as u}from"./vendor-react-BT-Op1j_.js";import{aH as Ce,aI as C,bP as Se,a6 as ke,s as c,y as F,z as $,H as z,a5 as R,K as M,B as _,f as Pe,N as Ee,d2 as D,W as Fe,Y as Me,Z as T,_ as L,ab as o,I as d,aO as I,am as ee,b0 as se,F as Te}from"./index-DgkqAiwu.js";import"./vendor-data-CqtBkUbK.js";import"./vendor-charts-F376sfYw.js";import"./vendor-editor-CAsPUtf2.js";import"./vendor-dnd-D3FEUJ2d.js";const Le=Ce({name:C().min(1,"Company name is required"),short_description:C().max(360,"Maximum 60 words (approx 360 characters)").optional(),description:C().optional(),showguide_entry:C().max(360,"Maximum 60 words (approx 360 characters)").optional(),website:C().trim().url("Invalid URL").optional().or(Se("")).nullable().transform(S=>S||""),booth_number:C().optional()}),ze=()=>{const S=we(),[te]=Ne(),p=te.get("modal")==="true",{toast:v}=ke(),[ae,q]=u.useState(!0),[V,Y]=u.useState(!1),[t,ie]=u.useState(null),[A,re]=u.useState(null),[H,J]=u.useState(""),[U,ne]=u.useState(null),[W,G]=u.useState(""),[g,x]=u.useState({}),[oe,le]=u.useState({}),[b,k]=u.useState({}),[ce,de]=u.useState({}),[y,O]=u.useState([]),[ue,me]=u.useState([]),[w,B]=u.useState([]),[pe,he]=u.useState([]),[K,ge]=u.useState("");u.useEffect(()=>{Z()},[]);const Z=async()=>{const{data:{session:a}}=await c.auth.getSession();if(!a){S("/exhibitor-portal/login");return}const{data:s,error:i}=await c.from("exhibitors").select("*").eq("user_id",a.user.id).maybeSingle();if(i){console.error("Error loading exhibitor:",i),v({title:"Error",description:"Failed to load exhibitor data",variant:"destructive"}),q(!1);return}if(!s){p||v({title:"No Exhibitor Profile",description:"Your exhibitor profile has not been set up yet. Please contact the admin.",variant:"destructive"}),q(!1),p||S("/exhibitor-portal");return}if(s){ie(s),s.logo_url&&J(s.logo_url),s.banner_url&&G(s.banner_url);const{data:n}=await c.from("exhibitor_social_media").select("*").eq("exhibitor_id",s.id).maybeSingle();n&&(x(n),le(n));const{data:f}=await c.from("exhibitor_address").select("*").eq("exhibitor_id",s.id).maybeSingle();f&&(k(f),de(f));const{data:m}=await c.from("exhibitor_contacts").select("*").eq("exhibitor_id",s.id);m&&(O(m),me(JSON.parse(JSON.stringify(m))));const{data:E}=await c.from("exhibitor_products").select("*").eq("exhibitor_id",s.id).order("sort_order",{ascending:!0}).order("created_at",{ascending:!0});E&&(B(E),he(JSON.parse(JSON.stringify(E))));const{data:N}=await c.from("event_settings").select("showguide_listing_deadline").order("updated_at",{ascending:!1}).limit(1).maybeSingle();N!=null&&N.showguide_listing_deadline&&ge(N.showguide_listing_deadline)}q(!1)},xe=a=>{var i;const s=(i=a.target.files)==null?void 0:i[0];if(s){if(s.size>5*1024*1024){v({title:"Error",description:"Logo file size must be less than 5MB",variant:"destructive"});return}re(s);const n=new FileReader;n.onloadend=()=>{J(n.result)},n.readAsDataURL(s)}},fe=a=>{var i;const s=(i=a.target.files)==null?void 0:i[0];if(s){if(s.size>5*1024*1024){v({title:"Error",description:"Banner file size must be less than 5MB",variant:"destructive"});return}ne(s);const n=new FileReader;n.onloadend=()=>{G(n.result)},n.readAsDataURL(s)}},je=async a=>{a.preventDefault(),Y(!0);try{const s=new FormData(a.currentTarget),i={name:s.get("name"),short_description:s.get("short_description"),description:s.get("description"),showguide_entry:s.get("showguide_entry"),website:s.get("website"),booth_number:s.get("booth_number")};Le.parse(i);let n=t==null?void 0:t.logo_url,f=t==null?void 0:t.banner_url;if(A){const r=A.name.split(".").pop(),l=`${t.id}-logo-${Date.now()}.${r}`,{error:j}=await c.storage.from("exhibitor-logos").upload(l,A,{upsert:!0});if(j)throw j;const{data:h}=c.storage.from("exhibitor-logos").getPublicUrl(l);n=h.publicUrl}if(U){const r=U.name.split(".").pop(),l=`${t.id}-banner-${Date.now()}.${r}`,{error:j}=await c.storage.from("exhibitor-logos").upload(l,U,{upsert:!0});if(j)throw j;const{data:h}=c.storage.from("exhibitor-logos").getPublicUrl(l);f=h.publicUrl}const m={};if(i.name!==((t==null?void 0:t.name)||"")&&(m.name=i.name),i.short_description!==((t==null?void 0:t.short_description)||"")&&(m.short_description=i.short_description),i.description!==((t==null?void 0:t.description)||"")&&(m.description=i.description),i.showguide_entry!==((t==null?void 0:t.showguide_entry)||"")&&(m.showguide_entry=i.showguide_entry),i.website!==((t==null?void 0:t.website)||"")&&(m.website=i.website),i.booth_number!==((t==null?void 0:t.booth_number)||"")&&(m.booth_number=i.booth_number),n!==(t==null?void 0:t.logo_url)&&(m.logo_url=n),f!==(t==null?void 0:t.banner_url)&&(m.banner_url=f),Object.keys(m).length>0){const{error:r}=await c.from("exhibitors").update({pending_changes:m,approval_status:"pending_approval",submitted_for_approval_at:new Date().toISOString()}).eq("id",t.id);if(r)throw r}const E=()=>["facebook","instagram","linkedin","twitter","tiktok","youtube"].some(l=>(g[l]||"")!==(oe[l]||"")),N=()=>["street_line_1","city","postcode","country"].some(l=>(b[l]||"")!==(ce[l]||""));if(E()){const{error:r}=await c.from("exhibitor_social_media").upsert({exhibitor_id:t.id,pending_changes:g,approval_status:"pending_approval",submitted_for_approval_at:new Date().toISOString()});if(r)throw r}if(N()){const{error:r}=await c.from("exhibitor_address").upsert({exhibitor_id:t.id,pending_changes:b,approval_status:"pending_approval",submitted_for_approval_at:new Date().toISOString()});if(r)throw r}for(const r of y){const l=ue.find(h=>h.id===r.id);if(!l||r.full_name!==l.full_name||r.email!==l.email||r.telephone!==l.telephone||r.job_title!==l.j
1ob_title||r.is_active!==l.is_active)if(r.id)await c.from("exhibitor_contacts").update({pending_changes:r,approval_status:"pending_approval",submitted_for_approval_at:new Date().toISOString()}).eq("id",r.id);else{const{data:h,error:X}=await c.from("exhibitor_contacts").insert({exhibitor_id:t.id,full_name:r.full_name,email:r.email,telephone:r.telephone,job_title:r.job_title,pending_changes:r,approval_status:"pending_approval",submitted_for_approval_at:new Date().toISOString()}).select("id");if(X)throw X;if(!h||h.length===0)throw new Error("Failed to save new contact. Please try again.")}}for(const r of w){const l=pe.find(h=>h.id===r.id);(!l||r.product_name!==l.product_name||r.description!==l.description||r.image_url!==l.image_url)&&(r.id?await c.from("exhibitor_products").update({pending_changes:r,approval_status:"pending_approval",submitted_for_approval_at:new Date().toISOString()}).eq("id",r.id):await c.from("exhibitor_products").insert({exhibitor_id:t.id,product_name:r.product_name,pending_changes:r,approval_status:"pending_approval",submitted_for_approval_at:new Date().toISOString()}))}try{await c.functions.invoke("notify-admin-submission",{body:{exhibitorId:t.id,exhibitorName:i.name,submissionType:"Profile & Listing Update",changedFields:Object.keys(m)}})}catch{}v({title:"Changes submitted for approval",description:"Your changes will be published once approved by an administrator"}),await Z()}catch(s){console.error("Error updating exhibitor:",s);const i=s instanceof Error?s.message:"Failed to update listing";v({title:"Error",description:i,variant:"destructive"})}finally{Y(!1)}},_e=()=>{O([...y,{full_name:"",email:"",telephone:"",job_title:"",is_active:!0}])},ve=async a=>{const s=y[a];s.id&&await c.from("exhibitor_contacts").delete().eq("id",s.id),O(y.filter((i,n)=>n!==a))},P=(a,s,i)=>{const n=[...y];n[a]={...n[a],[s]:i},O(n)},be=()=>{B([...w,{product_name:"",description:""}])},ye=async a=>{const s=w[a];s.id&&await c.from("exhibitor_products").delete().eq("id",s.id),B(w.filter((i,n)=>n!==a))},Q=(a,s,i)=>{const n=[...w];n[a]={...n[a],[s]:i},B(n)};return ae?e.jsx("div",{className:`flex items-center justify-center ${p?"p-12":"min-h-screen"}`,children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):t?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{titlePrefix:"Edit My Listing",description:"Manage your exhibitor profile",noIndex:!0}),e.jsxs("div",{className:"min-h-screen flex flex-col",children:[!p&&e.jsx(Ee,{}),e.jsx("main",{className:`flex-1 pb-12 ${p?"":"pt-page"}`,children:e.jsx("div",{className:"container mx-auto px-6",children:e.jsxs("div",{className:p?"":"flex gap-8 mt-[60px]",children:[!p&&e.jsx("aside",{className:"w-64 flex-shrink-0 sticky top-24 h-fit hidden lg:block",children:e.jsx(D,{exhibitorName:t==null?void 0:t.name,standNumber:t==null?void 0:t.booth_number,renderTrigger:!1,alwaysVisible:!0})}),!p&&e.jsx("div",{className:"lg:hidden fixed top-20 left-4 z-50",children:e.jsx(D,{exhibitorName:t==null?void 0:t.name,standNumber:t==null?void 0:t.booth_number,renderTrigger:!0})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs(F,{children:[e.jsxs($,{children:[e.jsx(z,{children:"Edit Your Listing"}),e.jsx(R,{children:"Manage your exhibitor profile, contacts, and products"})]}),e.jsx(M,{children:e.jsxs("form",{onSubmit:je,children:[e.jsxs(Fe,{defaultValue:"company",className:"w-full",children:[e.jsxs(Me,{className:"grid w-full grid-cols-5",children:[e.jsx(T,{value:"company",children:"Company"}),e.jsx(T,{value:"address",children:"Address"}),e.jsx(T,{value:"social",children:"Social Media"}),e.jsx(T,{value:"contacts",children:"Contacts"}),e.jsx(T,{value:"products",children:"Products"})]}),e.jsxs(L,{value:"company",className:"space-y-6 mt-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"name",children:"Company Name *"}),e.jsx(d,{id:"name",name:"name",defaultValue:t==null?void 0:t.name,required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"booth_number",children:"Booth Number"}),e.jsx(d,{id:"booth_number",name:"booth_number",defaultValue:t==null?void 0:t.booth_number})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"website",children:"Website"}),e.jsx(d,{id:"website",name:"website",type:"url",placeholder:"https://",defaultValue:t==null?void 0:t.website})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"short_description",children:"Short Description (Max 60 words)"}),e.jsx(I,{id:"short_description",name:"short_description",defaultValue:t==null?void 0:t.short_description,rows:3,placeholder:"Brief overview - no website, name, or bullet points"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Please don't include your website or your name as we'll add this in for you. No bulletpoints either."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"description",children:"Company Profile (Full Description)"}),e.jsx(I,{id:"description",name:"description",defaultValue:t==null?void 0:t.description,rows:6})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(o,{htmlFor:"showguide_entry",children:"Showguide Entry (Max 60 words)"}),K&&e.jsxs("span",{className:"text-xs font-semibold text-orange-600 dar
1k:text-orange-400",children:["Deadline: ",new Date(K).toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})]})]}),e.jsx(I,{id:"showguide_entry",name:"showguide_entry",defaultValue:t==null?void 0:t.showguide_entry,rows:3,placeholder:"Brief description for showguide (max 60 words)"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t!=null&&t.showguide_entry?Math.ceil(t.showguide_entry.length/6):0," / 60 words"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Company Logo"}),e.jsxs("div",{className:"flex items-center gap-4",children:[H&&e.jsx("img",{src:H,alt:"Logo",className:"h-20 w-20 object-contain rounded border"}),e.jsx(d,{type:"file",accept:"image/*",onChange:xe})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Exhibitor Banner (1250 x 350px recommended)"}),e.jsxs("div",{className:"flex items-center gap-4",children:[W&&e.jsx("img",{src:W,alt:"Banner",className:"h-20 w-40 object-cover rounded border"}),e.jsx(d,{type:"file",accept:"image/*",onChange:fe})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Max 5MB. Recommended: 1250 x 350px"})]})]}),e.jsxs(L,{value:"social",className:"space-y-6 mt-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Facebook"}),e.jsx(d,{value:g.facebook||"",onChange:a=>x(s=>({...s,facebook:a.target.value})),placeholder:"https://facebook.com/..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Instagram"}),e.jsx(d,{value:g.instagram||"",onChange:a=>x(s=>({...s,instagram:a.target.value})),placeholder:"https://instagram.com/..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"LinkedIn"}),e.jsx(d,{value:g.linkedin||"",onChange:a=>x(s=>({...s,linkedin:a.target.value})),placeholder:"https://linkedin.com/company/..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Twitter"}),e.jsx(d,{value:g.twitter||"",onChange:a=>x(s=>({...s,twitter:a.target.value})),placeholder:"https://twitter.com/..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"TikTok"}),e.jsx(d,{value:g.tiktok||"",onChange:a=>x(s=>({...s,tiktok:a.target.value})),placeholder:"https://tiktok.com/@..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"YouTube"}),e.jsx(d,{value:g.youtube||"",onChange:a=>x(s=>({...s,youtube:a.target.value})),placeholder:"https://youtube.com/@..."})]})]}),e.jsxs(L,{value:"address",className:"space-y-6 mt-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Street Address"}),e.jsx(d,{value:b.street_line_1||"",onChange:a=>k(s=>({...s,street_line_1:a.target.value}))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"City"}),e.jsx(d,{value:b.city||"",onChange:a=>k(s=>({...s,city:a.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Postcode"}),e.jsx(d,{value:b.postcode||"",onChange:a=>k(s=>({...s,postcode:a.target.value}))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Country"}),e.jsx(d,{value:b.country||"",onChange:a=>k(s=>({...s,country:a.target.value}))})]})]}),e.jsxs(L,{value:"contacts",className:"space-y-6 mt-6",children:[e.jsxs(_,{type:"button",onClick:_e,variant:"outline",className:"w-full",children:[e.jsx(ee,{className:"h-4 w-4 mr-2"})," Add Contact"]}),y.map((a,s)=>e.jsx(F,{children:e.jsxs(M,{className:"pt-6 space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("h4",{className:"font-semibold",children:["Contact ",s+1]}),e.jsx(_,{type:"button",variant:"destructive",size:"sm",onClick:()=>ve(s),children:e.jsx(se,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Full Name"}),e.jsx(d,{value:a.full_name,onChange:i=>P(s,"full_name",i.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Email"}),e.jsx(d,{type:"email",value:a.email,onChange:i=>P(s,"email",i.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Telephone"}),e.jsx(d,{value:a.telephone,onChange:i=>P(s,"telephone",i.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Job Title"}),e.jsx(d,{value:a.job_title,onChange:i=>P(s,"job_title",i.target.value)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:`active-${s}`,checked:a.is_active,onChange:i=>P(s,"is_active",i.target.checked),className:"rounded"}),e.jsx(o,{htmlFor:`active-${s}`,children:"Active"})]})]})},s))]}),e.jsxs(L,{value:"products",className:"space-y-6 mt-6",children:[e.jsxs(_,{type:"button",onClick:be,variant:"outline",className:"w-full",children:[e.jsx(ee,{className:"h-4 w-4 mr-2"})," Add Product"]}),w.map((a,s)=>e.jsx(F,{children:e.jsxs(M,{className:"pt-6 space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("h4",{className:"font-semibold",children:["Product ",s+1]}),e.jsx(_,{type:"button",variant:"destructive",size:"sm",onClick:()=>ye(s),children:e.jsx(se,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Product Name"}),e.jsx(d,{value:a.product_name,onChange:i=>Q(s,"product_name",i.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Description"}),e.jsx(I,{value:a.description,onChange:i=>Q(s,"description",i.target.value),rows:3})]})]})},s))]})]}),e.jsx("div",{className:"mt-6",children:e.jsx(_,{type:"submit",disabled:V,className:"w-full",children:V?"Saving...":"Save All Changes"})})]})})]})})]})})}),!p&&e.jsx(Te,{})]})]}):p?e.jsx("div",{className:"p-6",children:e.jsxs(F,{children:[e.jsxs($,{children:[e.jsx(z,{children:"No Exhibitor Profile"}),e.jsx(R,{children:"Your exhibitor profile has not been set up yet. Please contact the admin for assistance."})]}),e.jsx(M,{children:e.jsx(_,{onClick:()=>window.parent.postMessage("closeModal","*"),className:"w-full",children:"Close"})})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center p-6",children:e.jsxs(F,{className:"max-w-md",children:[e.jsxs($,{children:[e.jsx(z,{children:"No Exhibitor Profile"}),e.jsx(R,{children:"Your exhibitor profile has not been set up yet. Please contact the admin for assistance."})]}),e.jsx(M,{children:e.jsx(_,{onClick:()=>S("/exhibitor-portal"),className:"w-full",children:"Return to Portal Home"})})]})})};export{ze 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.