1import{_ as U}from"./ImageUploader.813e67df.js";import{_ as M}from"./Group.vue.a955ec46.js";import{u as T}from"./useToast.acdd6c2f.js";import{e as $,a as j,u as B,f as K,d as L,b as O}from"./entry.036824a3.js";import{u as q}from"./useImagesForm.b3c6e88b.js";import{m as G,a as g,an as H,b as k,p as A,k as W,N as y,W as J,V as Q,O as i,u as r,_ as C,R as V,a4 as X,P as Y,M as f,K as Z,j as D,n as ee}from"./swiper-vue.9554298b.js";import"./Icon.835a50bf.js";import"./config.aec7d9fd.js";const ae=i("div",{class:"flex flex-col md:flex-row md:items-center md:justify-between mb-6 gap-4"},[i("div",null,[i("h1",{class:"text-2xl font-bold text-gray-800"},"Image galleries Management"),i("p",{class:"text-sm text-gray-500 mt-1"},"Manage image galleries on your landing page.")])],-1),te=i("div",{class:"pt-2"},null,-1),se={class:"flex items-center justify-end gap-3 mt-4"},le={key:0,class:"text-blue-500 text-sm"},oe=["disabled"],re={key:0,class:"loading loading-spinner loading-sm"},_e=G({__name:"index",async setup(ie){let c,I;const n=T();$();const{requestOptions:F}=j(),o=g([]),d=g([]),m=g(!1),p=g(0),{data:u,pending:x,refresh:b,error:ne}=([c,I]=H(async()=>O("admin-gallery-images",async()=>{try{const e=await $fetch("/admin/galleries",{headers:{accept:"application/json"},method:"GET",...F});return console.log("â
API Response:",e),e}catch(e){throw console.error("â Failed to fetch gallery data:",e),n.error("Failed to load gallery images"),e}},{server:!1,lazy:!1,immediate:!0})),c=await c,I(),c),{saveImagesChangePosition:z,saveImagesPositionOnly:N,loading:v,uploadLoading:h,selectedItem:me,setSelectedItem:P,syncImages:_}=q([],{apiName:"galleries",identifierKey:"",customEndpoint:"/admin/galleries",customEndpointSaveImages:"/admin/save-galleries",useUrl:!1,callback:()=>{n.success("Saved successfully"),b()}});function w(e){if(console.log("ð¨ Initializing images...",e),!(e!=null&&e.data)||!Array.isArray(e.data)){console.warn("â ï¸ No valid data array found"),o.value=[],d.value=[],_([]);return}const t=e.data.map(a=>({id:a.id,image:a.image||a.url,url:a.image||a.url,name:a.name||`image-${a.id}`,fromServer:!0,file:null,size:0}));console.log("⨠Formatted images:",t),o.value=[...t],d.value=[...t],_([...t]),t.length>0&&P({id:t[0].id}),m.value=!0,p.value++}k(()=>u.value,e=>{console.log("ð Data watcher triggered:",e),e&&!m.value&&ee(()=>{w(e)})},{immediate:!0,deep:!0}),A(()=>
1{console.log("ðï¸ Component mounted"),setTimeout(()=>{u.value&&!m.value&&(console.log("ð§ Force initialize on mount"),w(u.value))},100)}),k(o,e=>{console.log("ð¸ Images array changed:",e.length),m.value&&_([...e])},{deep:!0});async function S(){var e,t;try{const a=o.value.filter(l=>!l.fromServer&&l.file instanceof File).map(l=>({file:l.file,link:l.link||""}));let s;if(a.length>0?s=await z(a):s=await N(),s!=null&&s.error)throw s.error;n.success("Changes saved successfully!"),await b()}catch(a){console.error("â Save error:",a);const s=((t=(e=a.response)==null?void 0:e._data)==null?void 0:t.error)||a;s.errors&&Array.isArray(s.errors)?s.errors.forEach(l=>{n.error(`${l.title}: ${l.message}`)}):n.error(s.title||"An unexpected error occurred.")}}W(()=>{var e,t;return{totalImages:o.value.length,initialImagesLength:d.value.length,serverImages:o.value.filter(a=>a.fromServer).length,newImages:o.value.filter(a=>!a.fromServer).length,hasData:!!u.value,isPending:x.value,isInitialized:m.value,dataLength:((t=(e=u.value)==null?void 0:e.data)==null?void 0:t.length)||0,uploaderKey:p.value}}),B({title:"Images galleries"});const{hasPermissionVisit:E}=K(),R=L();return A(()=>{E("landing_page")||R.push("/")}),(e,t)=>{const a=U,s=M;return f(),y(Y,null,[ae,J(s,{label:"",name:"image",classCustomLabel:"text-white",required:!0},{default:Q(()=>[te,(f(),Z(a,{key:r(p),modelValue:r(o),"onUpdate:modelValue":t[0]||(t[0]=l=>D(o)?o.value=l:null),name:"image",multiple:!0,cropEnabled:!1,"initial-images":r(d),onSubmit:S},null,8,["modelValue","initial-images"]))]),_:1}),i("div",se,[r(h)?(f(),y("div",le," Uploading "+C(r(o).filter(l=>!l.fromServer).length)+" images... ",1)):V("",!0),i("button",{onClick:S,type:"button",class:"btn text-white btn-primary",disabled:r(v)||r(h)||r(x)},[r(v)?(f(),y("span",re)):V("",!0),X(" "+C(r(v)?"Saving...":r(h)?"Uploading...":"Save All Images"),1)],8,oe)])],64)}}});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.