import{A as N}from"./ActionButton-6dFA985o.js";import{C as $}from"./ConfirmationDialog-Dsr1A4w6.js";import{H as I}from"./HeroSection-D-Cp_ogz.js";import{R as L}from"./ReusableDataTable-1-hRJNZ3.js";import{S as W}from"./SearchBox-eFhvvd_1.js";import{y as Y,z as x,T as j,g as d,c as P,W as q,ad as G,a as J,o as K,e as s,d as u,u as c,F as Q}from"./main-CJbVOHh0.js";import{u as X}from"./pagesStore-Dk9zCruQ.js";import{_ as Z}from"./_plugin-vue_export-helper-DlAUqK2U.js";/* empty css                                                                     */import"./pagesApi-bmNhyO8R.js";import"./cacheManager-C9fWw59Z.js";const ee={class:"pages-page-container"},te={class:"content-wrapper"},ae={class:"page-content"},oe={class:"toolbar"},se={class:"search-section"},le={class:"action-buttons"},ie={class:"table-container"},ne=10,re=500,ue={__name:"index",setup(de){const C=Y(),{user:p}=x(C),T=[{field:"title",header:"Title",sortable:!0,style:{width:"220px"},template:"user"},{field:"slug",header:"Slug",sortable:!0,style:{width:"200px"},template:"custom",customHTML:e=>`<div class="dt-table-slug">
         <i class="pi pi-link dt-table-slug__icon"></i>
         <span>/${e.slug}</span>
       </div>`},{field:"franchise_name",header:"Author",sortable:!0,style:{width:"180px"},template:"custom",customHTML:e=>`<div class="flex items-center gap-2">
         <i class="pi pi-user text-slate-400"></i>
         <span>${e.franchise_name||"System"}</span>
       </div>`},{field:"created_at",header:"Date Created",sortable:!0,type:"datetime",style:{width:"180px"}},{field:"status",header:"Status",sortable:!0,template:"badge",style:{width:"120px"}}],w=[{icon:"pi pi-pencil",tooltip:"Edit Page",severity:"info",action:"edit",to:e=>`/pages/edit/${e.id}`},{icon:"pi pi-trash",tooltip:"Delete Page",severity:"danger",action:"delete",condition:e=>{var t,o;return((o=(t=p.value)==null?void 0:t.data)==null?void 0:o.role)==="super_admin"?!0:typeof e.can_delete=="boolean"?e.can_delete:!1}}],m=j(),f=X(),{pages:v,total:R,loading:h,error:ce}=x(f),{fetchPages:D,deletePageById:F}=f,a=d({page:1,rows:ne,sortField:"",sortOrder:0,search:""}),k=P(()=>Array.isArray(v.value)?v.value:[]);async function l(){try{await D({...a.value})}catch{console.error("Failed to load pages")}}function B(e){a.value.page=e.page+1,a.value.rows=e.rows,l()}function E(e){a.value.sortField=e.sortField,a.value.sortOrder=Number(e.sortOrder||0),l()}let _=null;function b(){clearTimeout(_),_=setTimeout(()=>{a.value.page=1,l()},re)}function O(){m.push("/pages/add")}function z({action:e,rowData:t}){e.action==="edit"?m.push(`/pages/edit/${t.id}`):e.action==="delete"&&M(t)}const n=d(!1),y=d(null),i=d(null),H=P(()=>{var o,r;const e=i.value;return((r=(o=p.value)==null?void 0:o.data)==null?void 0:r.role)!=="super_admin"&&(e!=null&&e.is_global)&&(e==null?void 0:e.can_delete)===!0?"Remove your franchise override for this global page? Your site will use the super-admin page content again. This does not delete the global page.":"Are you sure you want to delete this page? This action cannot be undone."});function M(e){i.value=e,y.value=(e==null?void 0:e.id)??null,n.value=!0}async function U(){(await F(y.value)).status&&(n.value=!1,i.value=null,l())}function V(){n.value=!1,i.value=null}return q(l),G(l),(e,t)=>{var o,r,S,A;return K(),J(Q,null,[s("div",ee,[u(I,{title:"All Pages",subtitle:"Manage and organize your site pages",icon:"pi pi-file"}),s("div",te,[s("div",ae,[s("div",oe,[s("div",se,[u(W,{modelValue:a.value.search,"onUpdate:modelValue":t[0]||(t[0]=g=>a.value.search=g),placeholder:"Search pages...",loading:c(h),size:"medium",onSearch:b,onClear:t[1]||(t[1]=()=>{a.value.search="",b()}),class:"w-full"},null,8,["modelValue","loading"])]),s("div",le,[u(N,{label:"Add Page",icon:"pi pi-plus",class:"create-button",onClick:O})])]),s("div",ie,[u(L,{data:k.value,columns:T,actions:w,loading:c(h),"total-records":c(R),rows:a.value.rows,"sort-field":a.value.sortField,"sort-order":a.value.sortOrder,lazy:!0,paginator:!0,"rows-per-page-options":[10,25,50,100],"data-key":"id",onPage:B,onSort:E,onActionClick:z},null,8,["data","loading","total-records","rows","sort-field","sort-order"])])])])]),u($,{visible:n.value,"onUpdate:visible":t[2]||(t[2]=g=>n.value=g),title:((r=(o=c(p))==null?void 0:o.data)==null?void 0:r.role)!=="super_admin"&&((S=i.value)!=null&&S.is_global)&&((A=i.value)!=null&&A.can_delete)?"Remove franchise override":"Delete Page",message:H.value,item:null,loading:!1,onConfirm:U,onCancel:V},null,8,["visible","title","message"])],64)}}},xe=Z(ue,[["__scopeId","data-v-b7e60048"]]);export{xe as default};
