1import{_ as at}from"./t4-Ll4Fl.js";import{_ as lt}from"./t3G1b0As.js";import{_ as st}from"./BLyCKrf7.js";import{_ as nt}from"./5-TO8_S9.js";import{_ as it}from"./BcLSJ4YG.js";import{d as ot,A as rt,c as d,e as l,j as k,F as N,r as R,g as n,k as C,l as f,i as dt,m as v,G as F,o as u,n as $,t as p,h as T,D as ut,y as ct,f as b,H as E,v as w,p as pt}from"./Brsw7EL3.js";import{u as mt}from"./CDLjacJf.js";import{u as ft}from"./DxKzjjTg.js";import{u as bt}from"./ugE287kb.js";import"./CD1dWVWS.js";import"./BxrPWtJi.js";const xt={class:"flex gap-1 mb-4 bg-white rounded-xl p-1 border border-slate-200 flex-wrap"},_t=["onClick"],vt={key:0,class:"text-slate-300 text-sm leading-none"},gt={key:2,class:"chip bg-brand-teal-50 text-brand-teal-700 text-[10px]"},kt={class:"font-mono text-xs text-slate-600 break-all"},ht={key:0,class:"fa-solid fa-arrow-up-right-from-square text-[10px] text-slate-400 ml-1"},yt={class:"text-xs text-slate-500"},Ut={class:"flex items-start gap-2 bg-brand-teal-50 border border-brand-teal/20 rounded-xl p-3 text-xs text-brand-teal-700"},Vt={class:"flex items-center gap-2 cursor-pointer whitespace-nowrap"},Ct={class:"font-semibold"},$t={class:"grid grid-cols-1 md:grid-cols-2 gap-3"},Tt={class:"grid grid-cols-1 md:grid-cols-3 gap-3"},wt={id:"loc-list"},St=["value"],Mt={class:"flex gap-4 items-center"},Lt={class:"flex items-center gap-2 cursor-pointer"},Ot={class:"flex items-center gap-2 cursor-pointer"},At={key:0,class:"text-sm text-rose-600 bg-rose-50 border border-rose-200 rounded-xl px-3 py-2"},qt=["disabled"],Et={key:0,class:"fa-solid fa-spinner fa-spin"},Pt={key:1,class:"fa-solid fa-check"},Zt=ot({__name:"menus",setup(Dt){mt({title:"Menu - RS Persahabatan Admin"});const h=ft(),x=bt(),y=F({location:"header"}),m=v([]),L=v(["header","footer"]),O=v(!1),H=[{key:"order",label:"#",width:"60px",align:"center"},{key:"label",label:"Label (ID)",sortable:!1},{key:"url",label:"URL",sortable:!1,width:"260px"},{key:"parent_id",label:"Parent",sortable:!1,align:"center",width:"120px"},{key:"is_active",label:"Aktif",sortable:!1,align:"center",width:"80px"},{key:"actions",label:"",width:"110px",align:"right"}];function G(a){const t=(o,e)=>o.order-e.order||o.id-e.id,i=[],r=new Set;function U(o,e){i.push({...o,_depth:e}),r.add(o.id);const A=a.filter(q=>q.parent_id===o.id).sort(t);for(const q of A)U(q,e+1)}const V=a.filter(o=>o.parent_id===null).sort(t);for(const o of V)U(o,0);for(const o of a)r.has(o.id)||i.push({...o,_depth:0});return i}function P(a,t){const i=t.find(r=>r.id===a);return!i||i.parent_id==null?0:1+P(i.parent_id,t)}function j(a,t,i){let r=a;for(;r!=null;){if(r===t)return!0;r=i.find(V=>V.id===r)?.parent_id??null}return!1}async function S(){O.value=!0;try{const a=new URLSearchParams;y.location&&a.set("location",y.location);const t=await h.request(`/admin/menus?${a}`);if(t.success){m.value=G(t.data.items||[]);const i=new Set(["header","footer"]);for(const r of t.data.locations||[])i.add(r);L.value=[...i]}}catch(a){x.error("Gagal memuat data",a?.data?.message||"")}finally{O.value=!1}}function z(){S()}const K=pt(()=>{const a=m.value;return a.filter(t=>!(c.value&&t.id===c.value.id||c.value&&j(t.id,c.value.id,a)))});function D(a){return m.value.filter(t=>t.parent_id===a&&t.id!==c.value?.id).length+1}function I(a){s.parent_id=a,s.order=D(a)}function Y(a){const t=P(a.id,m.value);return`${"â ".repeat(t)}${a.label?.id||"(tanpa label)"}`}const _=v(!1),c=v(null),s=F({location:"header",parent_id:null,label_id:"",url:"",icon:"",order:0,target_blank:!1,is_active:!0,auto_translate:!0}),M=v(!1),g=v("");function Z(){c.value=null,s.location=y.location,s.parent_id=null,s.label_id="",s.url="/",s.icon="",s.order=D(null),s.target_blank=!1,s.is_active=!0,s.auto_translate=!0,g.value="",_.value=!0}function J(a){c.value=a,s.location=a.location,s.parent_id=a.parent_id,s.label_id=a.label?.id||"",s.url=a.url,s.icon=a.icon||"",s.order=a.order,s.target_blank=a.target_blank,s.is_active=a.is_active,s.auto_translate=!0,g.value="",_.value=!0}async function B(){g.value="",M.value=!0;try{const a={location:s.location,parent_id:s.parent_id||null,label:{id:s.label_id},url:s.url,icon:s.icon||null,order:Number(s.order),target_blank:s.target_blank,is_active:s.is_active,auto_translate:s.auto_translate};c.value?(await h.request(`/admin/menus/${c.value.id}`,{method:"PUT",body:a}),x.success("Menu diperbarui")):(await h.request("/admin/menus",{method:"POST",body:a}),x.success("Menu dibuat")),_.value=!1,S()}catch(a){g.value=a?.data?.message||a?.data?.error||"Gagal menyimpan"}finally{M.value=!1}}
1async function Q(a){if((await x.confirm({title:"Hapus menu?",text:`"${a.label?.id||"â"}" akan dihapus. Anak-anaknya juga ikut terhapus.`,confirmText:"Ya, hapus",icon:"warning",danger:!0})).isConfirmed)try{await h.request(`/admin/menus/${a.id}`,{method:"DELETE"}),x.success("Menu dihapus"),S()}catch(i){x.error("Gagal menghapus",i?.data?.message||"")}}async function W(a){const t=!a.is_active;try{await h.request(`/admin/menus/${a.id}`,{method:"PUT",body:{is_active:t,location:a.location,label:a.label,url:a.url,order:a.order,parent_id:a.parent_id,target_blank:a.target_blank,auto_translate:!1}}),a.is_active=t}catch(i){x.error("Gagal update",i?.data?.message||"")}}function X(a){return a?m.value.find(i=>i.id===a)?.label?.id||`#${a}`:"â"}function tt(a){return m.value.some(t=>t.parent_id===a)}function et(a){return m.value.filter(t=>t.parent_id===a).length}return rt(S),(a,t)=>{const i=at,r=lt,U=st,V=nt,o=it;return u(),d("div",null,[l("div",{class:"flex flex-col md:flex-row md:items-center md:justify-between gap-3 mb-4"},[t[12]||(t[12]=l("div",null,[l("h1",{class:"text-2xl font-display font-extrabold text-brand-ink-800"},[l("i",{class:"fa-solid fa-bars text-brand-teal mr-2"}),k("Menu ")]),l("p",{class:"text-slate-500 text-sm mt-1"},"Kelola navigasi di header, footer, dan lokasi lain di website publik.")],-1)),l("button",{class:"btn btn-primary self-start md:self-auto",onClick:Z},[...t[11]||(t[11]=[l("i",{class:"fa-solid fa-plus"},null,-1),k(" Tambah Menu ",-1)])])]),l("div",xt,[(u(!0),d(N,null,R(n(L),e=>(u(),d("button",{key:e,class:$(["px-4 py-1.5 rounded-lg text-sm font-semibold capitalize transition-colors",n(y).location===e?"bg-brand-teal text-white shadow-teal":"text-slate-600 hover:bg-slate-50"]),onClick:A=>{n(y).location=e,z()}},[l("i",{class:$(["fa-solid",e==="header"?"fa-compass":e==="footer"?"fa-shoe-prints":"fa-bars"])},null,2),k(" "+p(e),1)],10,_t))),128))]),C(U,{columns:H,rows:n(m),loading:n(O),"row-key":"id"},{"cell-order":f(({row:e})=>[l("span",{class:$(["chip font-mono",e._depth?"bg-slate-50 text-slate-400":"bg-slate-100 text-slate-600"])},p(e.order),3)]),"cell-label":f(({row:e})=>[l("div",{class:"flex items-center gap-2",style:ut(`padding-left: ${(e._depth||0)*28}px`)},[e._depth?(u(),d("span",vt,"â³")):T("",!0),e.icon?(u(),d("i",{key:1,class:$([e.icon,"text-brand-teal"])},null,2)):T("",!0),l("span",{class:$(["font-medium",e._depth===0?"text-slate-800":e._depth===1?"text-slate-600":"text-slate-500"])},p(e.label?.id||"â"),3),tt(e.id)?(u(),d("span",gt,[t[13]||(t[13]=l("i",{class:"fa-solid fa-layer-group text-[9px]"},null,-1)),k(" "+p(et(e.id))+" sub ",1)])):T("",!0)],4)]),"cell-url":f(({row:e})=>[l("span",kt,p(e.url),1),e.target_blank?(u(),d("i",ht)):T("",!0)]),"cell-parent_id":f(({row:e})=>[l("span",yt,p(X(e.parent_id)),1)]),"cell-is_active":f(({row:e})=>[C(i,{active:e.is_active,onToggle:A=>W(e)},null,8,["active","onToggle"])]),"cell-actions":f(({row:e})=>[C(r,{actions:[{label:"Edit",icon:"fa-solid fa-pen",variant:"edit",onClick:()=>J(e)},{label:"Hapus",icon:"fa-solid fa-trash",variant:"delete",onClick:()=>Q(e)}]},null,8,["actions"])]),_:1},8,["rows","loading"]),C(o,{modelValue:n(_),"onUpdate:modelValue":t[10]||(t[10]=e=>dt(_)?_.value=e:null),title:n(c)?"Edit Menu":"Tambah Menu",size:"lg"},{footer:f(()=>[l("button",{type:"button",class:"btn btn-ghost",onClick:t[9]||(t[9]=e=>_.value=!1)},"Batal"),l("button",{type:"button",class:"btn btn-primary",disabled:n(M),onClick:B},[n(M)?(u(),d("i",Et)):(u(),d("i",Pt)),k(" "+p(n(c)?"Simpan Perubahan":"Simpan"),1)],8,qt)]),default:f(()=>[l("form",{class:"space-y-4",onSubmit:ct(B,["prevent"])},[l("div",Ut,[t[14]||(t[14]=l("i",{class:"fa-solid fa-language text-brand-teal mt-0.5"},null,-1)),t[15]||(t[15]=l("div",{class:"flex-1"},[l("div",{class:"font-semibold mb-0.5"},"Auto-translate aktif"),l("div",{class:"text-slate-600"},"Label otomatis diterjemahkan ke EN, RU, KO, ZH saat simpan.")],-1)),l("label",Vt,[b(l("input",{"onUpdate:modelValue":t[0]||(t[0]=e=>n(s).auto_translate=e),type:"checkbox",class:"accent-brand-teal"},null,512),[[E,n(s).auto_translate]]),l("span",Ct,p(n(s).auto_translate?"ON":"OFF"),1)])]),l("div",null,[t[16]||(t[16]=l("label",{class:"block text-xs font-semibold text-slate-600 mb-1.5"},[k("Label "),l("span",{class:"text-rose-500"},"*")],-1)),b(l("input",{"onUpdate:modelValue":t[1]||(t[1]=e=>n(s).label_id=e),class:"input",required:"",minlength:"2",placeholder:"Tentang Kami"},null,512),[[w,n(s).label_id]])]),l("div",$t,[l("div",null,[t[17]||(t[17]=l("label",{class:"block text-xs font-semibold text-slate-600 mb-1.5"},"URL",-1)),b(l("input",{"onUpdate:modelValue":t[2]||(t[2]=e=>n(s).url=e),class:"input font-mono",required:"",placeholder:"/p/profil atau https://..."},null,512),[[w,n(s).url]])]),l("div",null,[t[18]||(t[18]=l("label",{class:"block text-xs font-semibold text-slate-600 mb-1.5"},"Icon (FontAwesome class)",-1)),b(l("input",{"onUpdate:modelValue":t[3]||(t[3]=e=>n(s).icon=e),class:"input font-mono",placeholder:"fa-solid fa-circle-info"},null,512),[[w,n(s).icon]])])]),l("div",Tt,[l("div",null,[t[19]||(t[19]=l("label",{class:"block text-xs font-semibold text-slate-600 mb-1.5"},"Lokasi",-1)),b(l("input",{"onUpdate:modelValue":t[4]||(t[4]=e=>n(s).location=e),class:"input",list:"loc-list",required:""},null,512),[[w,n(s).location]]),l("datalist",wt,[(u(!0),d(N,null,R(n(L),e=>(u(),d("option",{key:e,value:e},null,8,St))),128))])]),l("div",null,[t[20]||(t[20]=l("label",{class:"block text-xs font-semibold text-slate-600 mb-1.5"},"Parent",-1)),C(V,{modelValue:n(s).parent_id,"onUpdate:modelValue":[t[5]||(t[5]=e=>n(s).parent_id=e),I],options:[{value:null,label:"â Root (level 1) â"},...n(K).map(e=>({value:e.id,label:Y(e)}))]},null,8,["modelValue","options"]),t[21]||(t[21]=l("div",{class:"text-[11px] text-slate-400 mt-1"}," Kedalaman menu bebas â submenu boleh punya submenu lagi. ",-1))]),l("div",null,[t[22]||(t[22]=l("label",{class:"block text-xs font-semibold text-slate-600 mb-1.5"},"Urutan",-1)),b(l("input",{"onUpdate:modelValue":t[6]||(t[6]=e=>n(s).order=e),type:"number",min:"1",class:"input"},null,512),[[w,n(s).order,void 0,{number:!0}]]),t[23]||(t[23]=l("div",{class:"text-[11px] text-slate-400 mt-1"}," Terisi otomatis ke posisi terakhir saat parent dipilih. Bisa diubah manual. ",-1))])]),l("div",Mt,[l("label",Lt,[b(l("input",{"onUpdate:modelValue":t[7]||(t[7]=e=>n(s).target_blank=e),type:"checkbox",class:"accent-brand-teal"},null,512),[[E,n(s).target_blank]]),t[24]||(t[24]=l("span",{class:"text-sm text-slate-700"},"Buka di tab baru",-1))]),l("label",Ot,[b(l("input",{"onUpdate:modelValue":t[8]||(t[8]=e=>n(s).is_active=e),type:"checkbox",class:"accent-brand-teal"},null,512),[[E,n(s).is_active]]),t[25]||(t[25]=l("span",{class:"text-sm text-slate-700"},"Aktif",-1))])]),n(g)?(u(),d("div",At,p(n(g)),1)):T("",!0)],32)]),_:1},8,["modelValue","title"])])}}});
1export{Zt 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.