1import{j as e,aa as _,aD as C,aE as z,_ as $,aG as Q,aH as K,aC as W,bq as X,B as j,aN as Z,a2 as N,I as V,d as q,w as v,a9 as i}from"./index-BC9urIIf.js";import{i as Y,r as o}from"./vendor-Bl2pV9lf.js";import{T as ee}from"./textarea-C3ZwD-JK.js";import{L as h}from"./label-HAv_44a8.js";import{U as se,p as te,v as re,m as ae}from"./upload-validation-Ds_H19dw.js";import{U as oe}from"./UploadHinweis-gGs_RPDx.js";import{A as F}from"./award-DGYiF5Jz.js";import{U as E}from"./upload-CiR-6FyA.js";import{S as ne}from"./save-BaH9uvDF.js";import"./supabase-DTwkPJ-y.js";const f=se.sponsorLogo,A="[email protected]",B=`${A} / 0171 9823814`,ie={hauptsponsor:"Hauptsponsor",sponsor:"Sponsor",goodie_bag:"Goodie-Bag"};function be(){const{token:m}=Y(),[D,x]=o.useState(!0),[w,y]=o.useState(!1),[T,k]=o.useState(!1),[U,S]=o.useState(!1),[n,G]=o.useState(null),[H,O]=o.useState(!1),[a,l]=o.useState({logo_url:"",website_url:"",offer_title:"",offer_description:"",coupon_code:""}),[L,I]=o.useState(null),b=o.useRef(null);o.useEffect(()=>{(async()=>{if(!m){I("Ungültiger Link."),x(!1);return}const{data:t,error:u}=await v.rpc("get_sponsor_by_token",{p_token:m}),r=(t==null?void 0:t[0])||null;if(u||!r){I("Dieser Link ist ungültig oder abgelaufen."),x(!1);return}if(G({id:r.id,company_name:r.company_name,contact_person:r.contact_person,sponsor_type:r.sponsor_type}),l({logo_url:r.logo_url||"",website_url:r.website_url||"",offer_title:r.offer_title||"",offer_description:r.offer_description||"",coupon_code:r.coupon_code||""}),r.sponsor_type==="goodie_bag"){const{data:g}=await v.rpc("get_public_exhibitors"),p=(g||[]).some(c=>{var d;return((d=c.company_name)==null?void 0:d.toLowerCase().trim())===r.company_name.toLowerCase().trim()});O(p)}x(!1)})()},[m]);const M=async s=>{var g;const t=(g=s.target.files)==null?void 0:g[0];if(s.target.value="",!t||!n||!m)return;const u=te(t,f);if(u.ok===!1){i({title:u.title,description:u.description,variant:"destructive"});return}const r=await re(t,f);if(!r.valid){i({title:"Logo-Qualität unzureichend",description:r.message,variant:"destructive"});return}r.message&&i({title:"Logo-Qualität",description:r.message}),S(!0);try{const p=new FormData;p.append("edit_token",m),p.append("file",ae(t,u.mime));const c=await fetch("https://qaecdumsvkdjopzhxlfg.supabase.co/functions/v1/upload-sponsor-logo",{method:"POST",headers:{apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InFhZWNkdW1zdmtkam9wemh4bGZnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzU3NjkwNjcsImV4cCI6MjA5MTM0NTA2N30.3reE1kn506Xo8HM93uQLpaP-iigCbE4yAbR0fhWFVLM"},body:p});let d={};try{d=await c.json()}catch{}if(c.ok&&d.logo_url){l(J=>({...J,logo_url:d.logo_url})),i({title:"Logo hochgeladen!"});return}const R=c.status===403?"Dieser Link ist ungültig oder abgelaufen. Bitte fordern Sie einen neuen Link an.":c.status===404?`Der Logo-Upload ist gerade nicht erreichbar. Bitte schicken Sie Ihr Logo per E-Mail an ${A}.`:d.error||`Der Server antwortete mit Status ${c.status}.`;i({title:"Upload fehlgeschlagen",description:`${R} Bei Fragen: ${B}`,variant:"destructive"})}catch{i({title:"Upload fehlgeschlagen",description:`Die Verbindung wurde unterbrochen. Bitte prüfen Sie Ihre Internetverbindung und versuchen Sie es erneut. Bei Fragen: ${B}`,variant:"destructive"})}finally{S(!1)}},P=async()=>{if(!n)return;y(!0);const s={p_token:m,p_logo_url:a.logo_url||null,p_website_url:a.website_url.trim()||null};n.sponsor_type==="goodie_bag"&&(s.p_offer_title=a.offer_title.trim()||null,s.p_offer_description=a.offer_description.trim()||null,s.p_coupon_code=a.coupon_code.trim()||null);const{error:t}=await v.rpc("update_sponsor_by_token",s);y(!1),t?i({title:"Fehler beim Speichern",description:t.message,variant:"destructive"}):(k(!0),i({title:"Gespeichert!"}),setTimeout(()=>k(!1),3e3))};return D?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(_,{className:"w-8 h-8 animate-spin text-primary"})}):L||!n?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsx(C,{className:"max-w-md w-full",children:e.jsxs(z,{className:"pt-6 text-center",children:[e.jsx(F,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h2",{className:"text-lg font-semibold mb-2",children:"Link ungültig"}),e.jsx("p",{className:"text-muted-foreground",children:L||"Dieser Link ist ungültig."})]})})}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx($,{title:"Sponsor bearbeiten | Neuburger Hochzeitsmesse",description:"Sponsor-Eintrag bearbeiten.",noindex:!0}),e.jsx("div",{className:"bg-primary/5 border-b border-primary/10 py-8",children:e.jsxs("div",{className:"container mx-auto px-4 text-center",children:[e.jsx(F,{className:"w-10 h-10 text-primary mx-auto mb-3"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Sponsoren-Portal"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Neuburger Hochzeitsmesse â Logo & Werbematerial verwalten"})]})}),e.jsx("div",{className:"container mx-auto px-4 py-8 max-w-lg",children:e.jsxs(C,{children:[e.jsxs(Q,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(K,{className:"text-lg",children:n.company_name}),e.jsx(W,{variant:"outline",children:ie[n.sponsor_type]})]}),e.jsxs(X,{children:["Hallo ",n.contact_person,"! Laden Sie hier Ihr Firmenlogo hoch â es wird auf den Tickets und der Bestätigungsseite angezeigt."]})]}),e.jsxs(z,{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx(h,{className:"text-sm font-medium",children:"Firmenlogo *"}),e.jsxs("div",{className:"mt-2",children:[a.logo_url?e.jsxs("div",{className:"relative inline-block",children:[e.jsx("div",{className:"p-4 bg-white rounded-lg border shadow-sm",children:e.jsx("img",{src:a.logo_url,alt:"Logo",className:"max-h-24 max-w-[240px] object-contain"})}),e.jsx(j,{variant:"destructive",size:"icon",className:"absolute -top-2 -right-2 h-6 w-6",onClick:()=>l(s=>({...s,logo_url:""})),children:e.jsx(Z,{className:"w-3 h-3"})})]}):e.jsx("div",{className:"border-2 border-dashed border-border rounded-lg p-8 text-center cursor-pointer hover:border-primary/50 transition-colors",onClick:()=>{var s;return(s=b.current)==null?void 0:s.click()},children:U?e.jsx(_,{className:"w-8 h-8 animate-spin text-primary mx-auto"}):e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"w-8 h-8 text-muted-foreground mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Klicken zum Hochladen"})]})}),e.jsx(oe,{regel:f,className:"mt-2"}),e.jsx("input",{ref:b,type:"file",accept:f.accept,className:"hidden",onChange:M}),a.logo_url&&e.jsxs(j,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>{var s;return(s=b.current)==null?void 0:s.click()},children:[e.jsx(E,{className:"w-3 h-3 mr-1"})," Logo ersetzen"]})]})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"sponsoredit-website-url",className:"text-sm font-medium",children:"Website"}),e.jsx(N,{id:"sponsoredit-website-url",value:a.website_url,onChange:s=>l(t=>({...t,website_url:s.target.value})),placeholder:"https://www.ihre-firma.de",className:"mt-1"})]}),n.sponsor_type==="goodie_bag"&&e.jsxs(e.Fragment,{children:[H&&e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-primary/5 p-3 flex items-start gap-2",children:[e.jsx(V,{className:"w-4 h-4 text-primary shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-xs text-foreground",children:["Dieses Angebot kann auch im Aussteller-Portal unter ",e.jsx("strong",{children:"Goodie-Bag"})," bearbeitet werden â beide Quellen werden auf der Aussteller-Seite zusammengeführt."]})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"sponsoredit-offer-title",className:"text-sm font-medium",children:"Angebots-Titel"}),e.jsx(N,{id:"sponsoredit-offer-title",value:a.offer_title,onChange:s=>l(t=>({...t,offer_title:s.target.value})),placeholder:"z.B. 10% Rabatt auf Brautmode",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"sponsoredit-offer-description",className:"text-sm font-medium",children:"Beschreibung"}),e.jsx(ee,{id:"sponsoredit-offer-description",value:a.offer_description,onChange:s=>l(t=>({...t,offer_description:s.target.value})),placeholder:"Details zum Angebot...",rows:3,className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"sponsoredit-coupon-code",className:"text-sm font-medium",children:"Gutscheincode"}),e.jsx(N,{id:"sponsoredit-coupon-code",value:a.coupon_code,onChange:s=>l(t=>({...t,coupon_code:s.target.value})),placeholder:"z.B. MESSE2026",className:"mt-1 font-mono"})]})]}),e.jsx(j,{onClick:P,disabled:w,className:"w-full",size:"lg",children:w?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"w-4 h-4 mr-2 animate-spin"})," Speichern..."]}):T?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 mr-2"})," Gespeichert!"]}):e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4 mr-2"})," Ãnderungen speichern"]})}),e.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Sie können diesen Link jederzeit erneut aufrufen um Ihre Daten zu bearbeiten."})]})]})})]})}export{be 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.