1import{b as U,aa as S,r as g,a as E,s as i,ax as q,j as e,n as w,q as b,G as h,o as B,p as I,N as M,B as m,X as v,R as _,U as z,Z as D,I as F,bo as A,k as c}from"./index-DH-BokCi.js";import{A as R}from"./award-CBTacqdu.js";function O(){const{user:s}=U(),k=S(),n=g.useRef(null),[o,x]=g.useState(!1),[C,l]=g.useState(!1),{data:u,isLoading:P}=E({queryKey:["premium-partner-logo",s==null?void 0:s.id],queryFn:async()=>{if(!s)return null;const{data:r,error:a}=await i.from("marketing_salesperson_profiles").select("premium_partner_logo_url").eq("user_id",s.id).maybeSingle();if(a)throw a;return(r==null?void 0:r.premium_partner_logo_url)||null},enabled:!!(s!=null&&s.id)}),d=q({mutationFn:async r=>{if(!s)throw new Error("Nicht angemeldet");const{data:a}=await i.from("marketing_salesperson_profiles").select("id").eq("user_id",s.id).maybeSingle();if(a){const{error:t}=await i.from("marketing_salesperson_profiles").update({premium_partner_logo_url:r,updated_at:new Date().toISOString()}).eq("user_id",s.id);if(t)throw t}else{const{error:t}=await i.from("marketing_salesperson_profiles").insert({user_id:s.id,premium_partner_logo_url:r});if(t)throw t}},onSuccess:()=>{k.invalidateQueries({queryKey:["premium-partner-logo",s==null?void 0:s.id]}),c.success("Premiumpartner-Logo gespeichert")},onError:r=>c.error("Fehler beim Speichern: "+r.message)}),f=async r=>{var t;const a=(t=r.target.files)==null?void 0:t[0];if(!(!a||!s)){if(!a.type.startsWith("image/")){c.error("Bitte nur Bilddateien hochladen");return}if(a.size>5*1024*1024){c.error("Maximale DateigröÃe: 5MB");return}x(!0);try{const p=a.name.split(".").pop(),N=`premium-partner-logo/${s.id}/${Date.now()}.${p}`,{error:y}=await i.storage.from("marketing-assets").upload(N,a,{upsert:!0});if(y)throw y;const{data:L}=i.storage.from("marketing-assets").getPublicUrl(N);await d.mutateAsync(L.publicUrl)}catch(p){c.error("Upload fehlgeschlagen: "+p.message)}finally{x(!1),n.current&&(n.current.value="")}}},j=r=>{r.trim()&&d.mutate(r.trim()),l(!1)};return P?e.jsx(w,{children:e.jsx(b,{className:"p-8 flex items-center justify-center",children:e.jsx(h,{className:"h-6 w-6 animate-spin text-muted-foreground"})})}):e.jsxs(w,{children:[e.jsxs(B,{children:[e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-5 w-5"}),"Premiumpartner-Logo"]}),e.jsxs(M,{children:["Optional: Lade dein eigenes Firmen-/Partner-Logo hoch. Auf der Kundenansicht erscheint dann",e.jsx("span",{className:"font-medium",children:' âWärmekraft Premiumpartner / [dein Logo]"'})," im Header."]})]}),e.jsx(b,{className:"space-y-4",children:u?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative rounded-xl border-2 border-dashed border-border bg-muted/30 p-6 flex items-center justify-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Wärmekraft Premiumpartner"}),e.jsx("span",{className:"text-muted-foreground",children:"/"}),e.jsx("img",{src:u,alt:"Premiumpartner-Logo",className:"max-h-16 max-w-[200px] object-contain",onError:r=>{r.target.src="/placeholder.svg"}}),e.jsx(m,{variant:"destructive",size:"icon",className:"absolute top-2 right-2 h-8 w-8",onClick:()=>d.mutate(null),disabled:d.isPending,children:e.jsx(v,{className:"h-4 w-4"})})]}),e.jsx(_,{value:u,readOnly:!0,className:"text-xs text-muted-foreground"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:n,type:"file",accept:"image/*",onChange:f,className:"hidden"}),e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>{var r;return(r=n.current)==null?void 0:r.click()},disabled:o,children:[o?e.jsx(h,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(z,{className:"h-4 w-4 mr-2"}),"Ersetzen"]})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:D("rounded-xl border-2 border-dashed border-border bg-muted/20 p-8 flex flex-col items-center justify-center gap-3 cursor-pointer hover:border-primary/40 hover:bg-muted/40 transition-colors",o&&"pointer-events-none opacity-60"),onClick:()=>{var r;return!o&&((r=n.current)==null?void 0:r.click())},children:[o?e.jsx(h,{className:"h-10 w-10 text-muted-foreground animate-spin"}):e.jsx(F,{className:"h-10 w-10 text-muted-foreground"}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-medium text-sm",children:"Premiumpartner-Logo hochladen"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"PNG, JPG oder SVG ⢠Max. 5MB"})]})]}),e.jsx("input",{ref:n,type:"file",accept:"image/*",onChange:f,className:"hidden"}),C?e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_,{placeholder:"https://...",autoFocus:!0,onBlur:r=>{r.target.value?j(r.target.value):l(!1)},onKeyDown:r=>{r.key==="Enter"&&j(r.target.value),r.key==="Escape"&&l(!1)}}),e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>l(!1),children:e.jsx(v,{className:"h-4 w-4"})})]}):e.jsxs(m,{variant:"ghost",size:"sm",onClick:()=>l(!0),className:"gap-2 text-muted-foreground",children:[e.jsx(A,{className:"h-4 w-4"})," Oder URL eingeben"]})]})})]})}
1export{O as MarketingPremiumPartnerLogo};
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.