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