import{d as C}from"./datatables-I6jthWPb.js";import{r as I,g as j}from"./api-DZ3cXm1m.js";import{i as k}from"./tooltip-manager-D9RaGGY4.js";import"./bootstrap.esm-Bb7dPm-H.js";import"./datatables-Bo82YvhT.js";/* empty css                                  */document.addEventListener("DOMContentLoaded",function(){var m,p,g,f,b,h;const c=document.getElementById("pagesTable");if(!c)return;const y=c.getAttribute("data-records-url"),l=window.pageConfig||{translations:{},routes:{},locales:[]},T=((m=document.querySelector('meta[name="csrf-token"]'))==null?void 0:m.getAttribute("content"))||"",a=e=>String(e??"").replace(/[&<>"']/g,n=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[n]),r=$("#pagesTable").DataTable({...C.getDefaultConfig(),serverSide:!0,searching:!0,ordering:!1,dom:'<"d-flex justify-content-between align-items-center mb-3"<"d-flex align-items-center"l><"d-flex align-items-center"f>>t<"d-flex justify-content-between align-items-center mt-3"<"d-flex align-items-center"i><"d-flex align-items-center"p>>',ajax:{url:y,type:"GET",data:function(e){var n,i,o;e.brand_id=((n=document.getElementById("pageBrandFilter"))==null?void 0:n.value)||"",e.locale=((i=document.getElementById("pageLocaleFilter"))==null?void 0:i.value)||"",e.status=((o=document.getElementById("pageStatusFilter"))==null?void 0:o.value)||""},beforeSend:function(e){e.setRequestHeader("Authorization",`Bearer ${j()}`)},error:async function(e){e.status===401&&await I()&&r.ajax.reload()}},columns:[{data:null,name:"brand",render:e=>e.brand_id?"#"+e.brand_id:a(l.translations.master??"—")},{data:null,name:"title",render:e=>{const n=e.is_home?'<span title="Home" class="text-warning ms-1">🏠</span>':"",i=l.locales||[],o=(e.translations||[]).map(t=>t.locale),d=i.filter(t=>!o.includes(t)),s=(e.translations||[]).map(t=>{const E=t.status==="published"?"pb-locale-chip--published":"pb-locale-chip--draft",v=t.status==="published"?l.translations.published:l.translations.draft,L=t.slug?"/"+a(t.slug):"",B=t.is_home?" • home":"";return`<a href="${a(t.edit_url)}" class="pb-locale-chip ${E}" title="${a(v)} • ${L}${B}">${a(t.locale.toUpperCase())}</a>`}).join(""),x=d.map(t=>`<button type="button" class="pb-locale-chip pb-locale-chip--add" data-add-translation="${e.id}" data-locale="${a(t)}" title="${a(l.translations.addTranslation||"Add translation")} (${a(t.toUpperCase())})">+ ${a(t.toUpperCase())}</button>`).join("");return`<div class="d-flex align-items-center flex-wrap gap-2"><strong>${a(e.title)}</strong>${n}<span class="pb-locale-chips">${s}${x}</span></div>`}},{data:"slug",name:"slug",render:e=>`<code>${a(e||"/")}</code>`},{data:"updated_by",name:"updated_by",render:e=>`<small class="text-muted">${a(e||"-")}</small>`},{data:null,name:"actions",orderable:!1,searchable:!1,className:"text-end",render:e=>`<a href="${a(e.edit_url)}" class="btn btn-sm btn-outline-primary d-inline-flex align-items-center justify-content-center" style="width: 32px; height: 32px;" data-bs-toggle="tooltip" title="${a(l.translations.edit||"Edit")}"><i class="fas fa-edit"></i></a>`}],drawCallback:function(){k()}});(p=document.getElementById("pageBrandFilter"))==null||p.addEventListener("change",()=>r.ajax.reload()),(g=document.getElementById("pageLocaleFilter"))==null||g.addEventListener("change",()=>r.ajax.reload()),(f=document.getElementById("pageStatusFilter"))==null||f.addEventListener("change",()=>r.ajax.reload()),(b=document.getElementById("pagesTableToggleFilters"))==null||b.addEventListener("click",()=>{const e=document.getElementById("pagesTableFilters");e&&(e.style.display=e.style.display==="none"?"":"none")});let u;(h=document.getElementById("pagesTableSearch"))==null||h.addEventListener("input",e=>{clearTimeout(u),u=setTimeout(()=>r.search(e.target.value).draw(),300)}),document.body.addEventListener("click",e=>{const n=e.target.closest("[data-add-translation]");if(!n)return;e.preventDefault();const i=n.dataset.addTranslation,o=n.dataset.locale,d=l.routes.addTranslation.replace(":id",i),s=document.createElement("form");s.method="POST",s.action=d,s.innerHTML=`
            <input type="hidden" name="_token" value="${T}">
            <input type="hidden" name="locale" value="${o}">
        `,document.body.appendChild(s),s.submit()})});
