1import{r as u,ab as Y,c as G,z as B,Q as H,o as c,a as L,w as J,b as t,d as T,u as j,ah as K,h as _,f as v,t as g,g as x,i as X,s as V,v as $,L as E,D as U}from"./LoginModal-v__rASBc.js";import{S as Z}from"./app-in6zgkpf.js";import{T as ee}from"./trash-2-BKjH467x.js";import"./_commonjsHelpers-D6-XlEtG.js";/* empty css */import"./echo-fvvHJG-1.js";import"./listingImageRemint-DdzXd0Qc.js";const te={class:"flex flex-col h-full"},oe={class:"px-6 pt-4"},se={class:"flex-1 overflow-y-auto p-6 space-y-5"},ne={key:0,class:"rounded-xl bg-red-50 border border-red-200 p-3 text-sm text-red-700"},le={key:1,class:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700"},re={class:"flex items-start gap-4"},ae={class:"relative"},ie={key:0,class:"absolute inset-0 flex items-center justify-center text-2xl font-bold text-white/60"},de={class:"flex-1"},ue={class:"flex items-center gap-2"},ce={class:"flex items-center gap-1.5"},me={key:2,class:"rounded-xl bg-stone-50border border-stone-100 p-4"},pe={class:"text-sm text-stone-600"},fe={class:"font-medium text-stone-900"},be={class:"border-t border-stone-100 pt-5"},ve={key:0},ge={key:1,class:"rounded-xl bg-red-50 border border-red-200 p-4"},xe={class:"flex gap-2"},we=["disabled"],ye={class:"flex-shrink-0 border-t border-stone-200 px-6 py-4"},ke={class:"flex items-center justify-end gap-3"},he=["disabled"],De={__name:"NetworkEditorModal",props:{modelValue:{type:Boolean,default:!1},network:{type:Object,default:null}},emits:["update:modelValue","updated","deleted","back"],setup(y,{emit:P}){const d=y,D=P,k=u(!1),I=u(!1),m=u(""),w=u(""),M=u(null),F=u(null),p=u(null),h=u(null),C=u(!1),z=u(!1),n=Y({name:"",primary_brand_colour:"#ffffff",website:"",description:""}),N=G(()=>{var s;return(s=d.network)!=null&&s.is_franchise?"Franchise":"Network"});B(()=>d.modelValue,s=>{s&&d.network&&(n.name=d.network.name||"",n.primary_brand_colour=d.network.primary_brand_colour||"#ffffff",n.website=d.network.website||"",n.description=d.network.description||"",p.value=d.network.logo||null,h.value=null,m.value="",w.value="",C.value=!1,H(()=>S()))}),B(()=>n.primary_brand_colour,()=>S());const S=()=>{const s=F.value;if(!s)return;const e=s.getContext("2d");if(e.fillStyle=n.primary_brand_colour||"#ffffff",e.fillRect(0,0,s.width,s.height),p.value){const o=new Image;o.crossOrigin="anonymous",o.onload=()=>{const f=Math.min(s.width,s.height)*.8,l=Math.min(f/o.width,f/o.height),a=o.width*l,i=o.height*l;e.drawImage(o,(s.width-a)/2,(s.height-i)/2,a,i)},o.src=p.value}},R=s=>new Promise(e=>{const o=document.createElement("canvas"),f=o.getContext("2d");o.width=100,o.height=100;try{f.drawImage(s,0,0,100,100);const l=f.getImageData(0,0,100,100).data,a={};for(let r=0;r<l.length;r+=4){if(l[r+3]<128||l[r]>240&&l[r+1]>240&&l[r+2]>240||l[r]<20&&l[r+1]<20&&l[r+2]<20)continue;const b=`${Math.round(l[r]/16)*16},${Math.round(l[r+1]/16)*16},${Math.round(l[r+2]/16)*16}`;a[b]||(a[b]={count:0,r:0,g:0,b:0}),a[b].count++,a[b].r+=l[r],a[b].g+=l[r+1],a[b].b+=l[r+2]}let i=null;for(const r of Object.values(a))(!i||r.count>i.count)&&(i=r);if(i){const r="#"+[i.r,i.g,i.b].map(b=>Math.round(b/i.count).toString(16).padStart(2,"0")).join("");e(r)}else e(null)}catch{e(null)}}),O=s=>{var f;const e=(f=s.target.files)==null?void 0:f[0];if(!e)return;h.value=e;const o=new FileReader;o.onload=l=>{p.value=l.target.result;const a=new Image;a.onload=async()=>{const i=await R(a);i&&(n.primary_brand_colour=i),S()},a.src=l.target.result},o.readAsDataURL(e)},A=()=>{h.value=null,p.value=null,M.value&&(M.value.value=""),S()},q=async()=>{var s,e;if(!n.name.trim()){m.value="Name is required";return}k.value=!0,m.value="",w.value="";try{if(await U.patch(`/admin/crm/networks/${d.network.id}`,{name:n.name,primary_brand_colour:n.primary_brand_colour,website:n.website||null,description:n.description||null}),h.value){I.value=!0;const o=new FormData;o.append("logo",h.value),await U.post(`/admin/crm/networks/${d.network.id}/logo`,o,{headers:{"Content-Type":"multipart/form-data"}}),I.value=!1}w.value="Saved successfully",D("updated"),setTimeout(()=>{w.value=""},2e3)}catch(o){m.value=((e=(s=o.response)==null?void 0:s.data)==null?void 0:e.message)||"Failed to save"}finally{k.value=!1}},Q=async()=>{var s,e;z.value=!0,m.value="";try{await U.delete(`/admin/crm/networks/${d.network.id}`),D("deleted"),D("update:modelValue",!1)}catch(o){m.value=((e=(s=o.response)==null?void 0:s.data)==null?void 0:e.message)||"Failed to delete",C.value=!1}finally{z.value=!1}},W=s=>s?s.split(" ").map(e=>e[0]).join("").substring(0,2).toUpperCase():"?";return(s,e)=>(c(),L(Z,{"model-value":y.modelValue,"onUpdate:modelValue":e[10]||(e[10]=o=>s.$emit("update:modelValue",o)),title:`Edit ${N.value}`,width:"480px"},{default:J(()=>[t("div",te,[t("div",oe,[t("button",{type:"button",onClick:e[0]||(e[0]=o=>s.$emit("back")),class:"inline-flex items-center gap-1 text-sm text-stone-500 hover:text-stone-700 transition-colors"},[T(j(K),{class:"size-4"}),e[11]||(e[11]=_(" Back to list ",-1))])]),t("div",se,[m.value?(c(),v("div",ne,g(m.value),1)):x("",!0),w.value?(c(),v("div",le,g(w.value),1)):x("",!0),t("div",null,[e[14]||(e[14]=t("label",{class:"mb-2 block text-sm font-medium text-stone-700"},"Logo",-1)),t("div",re,[t("div",ae,[t("div",{class:"flex size-[100px] items-center justify-center overflow-hidden rounded-xl border border-stone-200",style:X({backgroundColor:n.primary_brand_colour})},[t("canvas",{ref_key:"logoPreviewCanvas",ref:F,width:"200",height:"200",class:"max-h-full max-w-full object-contain"},null,512),p.value?x("",!0):(c(),v("div",ie,g(W(n.name)),1))],4),p.value?(c(),v("button",{key:0,onClick:A,type:"button",class:"absolute -right-1.5 -top-1.5 flex size-5 items-center justify-center rounded-full bg-gray-900 text-white shadow-sm hover:bg-gray-700"},[...e[12]||(e[12]=[t("svg",{class:"size-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])])):x("",!0)]),t("div",de,[t("input",{ref_key:"logoFileInput",ref:M,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",class:"hidden",onChange:O},null,544),t("button",{onClick:e[1]||(e[1]=o=>s.$refs.logoFileInput.click()),type:"button",class:"mb-2 w-full rounded-xl border border-stone-200 bg-white px-4 py-2 text-sm font-medium text-stone-700 transition-colors hover:bg-stone-50"},g(p.value?"Change Image":"Choose Image"),1),t("div",ue,[e[13]||(e[13]=t("label",{class:"text-xs text-stone-500"},"Brand Colour:",-1)),t("div",ce,[V(t("input",{"onUpdate:modelValue":e[2]||(e[2]=o=>
1n.primary_brand_colour=o),type:"color",class:"size-7 cursor-pointer rounded border border-stone-200"},null,512),[[$,n.primary_brand_colour]]),V(t("input",{"onUpdate:modelValue":e[3]||(e[3]=o=>n.primary_brand_colour=o),type:"text",class:"w-20 rounded border border-stone-200 px-2 py-1 font-mono text-xs",placeholder:"#ffffff"},null,512),[[$,n.primary_brand_colour]])])])])])]),t("div",null,[e[15]||(e[15]=t("label",{class:"mb-1.5 block text-sm font-medium text-stone-700"},"Name *",-1)),V(t("input",{"onUpdate:modelValue":e[4]||(e[4]=o=>n.name=o),type:"text",class:"w-full rounded-xl border border-stone-200 px-3 py-2.5 text-sm focus:border-pink-400 focus:outline-none focus:ring-1 focus:ring-pink-400"},null,512),[[$,n.name]])]),t("div",null,[e[16]||(e[16]=t("label",{class:"mb-1.5 block text-sm font-medium text-stone-700"},"Website",-1)),V(t("input",{"onUpdate:modelValue":e[5]||(e[5]=o=>n.website=o),type:"url",placeholder:"https://www.example.com",class:"w-full rounded-xl border border-stone-200 px-3 py-2.5 text-sm focus:border-pink-400 focus:outline-none focus:ring-1 focus:ring-pink-400"},null,512),[[$,n.website]])]),t("div",null,[e[17]||(e[17]=t("label",{class:"mb-1.5 block text-sm font-medium text-stone-700"},"Description",-1)),V(t("textarea",{"onUpdate:modelValue":e[6]||(e[6]=o=>n.description=o),rows:"3",class:"w-full resize-none rounded-xl border border-stone-200 px-3 py-2.5 text-sm focus:border-pink-400 focus:outline-none focus:ring-1 focus:ring-pink-400"},null,512),[[$,n.description]])]),y.network?(c(),v("div",me,[t("div",pe,[t("span",fe,g(y.network.member_count||y.network.brands_count||0),1),e[18]||(e[18]=_(" member brands ",-1))])])):x("",!0),t("div",be,[C.value?(c(),v("div",ge,[e[20]||(e[20]=t("p",{class:"text-sm text-red-700 mb-3"},"Are you sure? This cannot be undone.",-1)),t("div",xe,[t("button",{type:"button",onClick:Q,disabled:z.value,class:"inline-flex items-center gap-1.5 rounded-lg bg-red-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-red-700 disabled:opacity-50"},[z.value?(c(),L(j(E),{key:0,class:"size-3.5 animate-spin"})):x("",!0),e[19]||(e[19]=_(" Yes, delete ",-1))],8,we),t("button",{type:"button",onClick:e[8]||(e[8]=o=>C.value=!1),class:"rounded-lg px-3 py-1.5 text-sm font-medium text-stone-600 hover:bg-stone-100"}," Cancel ")])])):(c(),v("div",ve,[t("button",{type:"button",onClick:e[7]||(e[7]=o=>C.value=!0),class:"inline-flex items-center gap-1.5 text-sm text-red-600 hover:text-red-700 transition-colors"},[T(j(ee),{class:"size-4"}),_(" Delete "+g(N.value),1)])]))])]),t("div",ye,[t("div",ke,[t("button",{type:"button",onClick:e[9]||(e[9]=o=>s.$emit("update:modelValue",!1)),class:"rounded-xl px-4 py-2.5 text-sm font-medium text-stone-600 hover:bg-stone-100 transition-colors"}," Cancel "),t("button",{type:"button",onClick:q,disabled:k.value||!n.name.trim(),class:"flex items-center gap-2 rounded-xl bg-gradient-to-r from-rose-500 to-pink-500 px-5 py-2.5 text-sm font-medium text-white shadow-sm transition-all hover:from-rose-600 hover:to-pink-600 hover:shadow disabled:cursor-not-allowed disabled:opacity-50"},[k.value?(c(),L(j(E),{key:0,class:"size-4 animate-spin"})):x("",!0),_(" "+g(k.value?I.value?"Uploading logo...":"Saving...":"Save Changes"),1)],8,he)])])])]),_:1},8,["model-value","title"]))}};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.