import{u as ae}from"./programStore-DrqG5Rww.js";import{z as _,y as te,T as oe,g as r,c as n,W as se,ad as re,a as ne,o as $,d as p,e as l,u as b,p as le,b as ie}from"./main-CJbVOHh0.js";import{S as de}from"./SearchBox-eFhvvd_1.js";import{u as ce}from"./settingStore-DBFwe1tS.js";import{C as ue}from"./ConfirmationDialog-Dsr1A4w6.js";import{H as me}from"./HeroSection-D-Cp_ogz.js";import{R as ge}from"./ReusableDataTable-1-hRJNZ3.js";import{A as pe}from"./ActionButton-6dFA985o.js";import{l as H}from"./languageCode-D4o6NugM.js";import{_ as ve}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./cacheManager-C9fWw59Z.js";/* empty css                                                                     */const fe={class:"programs-page-container"},he={class:"content-wrapper"},_e={class:"page-content"},be={class:"toolbar"},ye={class:"search-section"},we={class:"action-buttons"},Ce={class:"table-container"},Se={__name:"index",setup(Pe){const i=ae(),{programs:y,total:M,loading:w,reordering:Ae}=_(i),F=te(),{user:u}=_(F),C=ce(),{setting:v}=_(C),S=oe(),t=r({page:1,rows:50,sortField:"order_no",sortOrder:1,search:""}),P=r([]),d=r(!1),A=r(""),m=r(null),f=r(new Set);n(()=>P.value.map(e=>e.id)),n(()=>P.value.length>0);const N=n(()=>{var x,k,L,D,T,z,B,E,R,V,W;const e=((k=(x=v.value)==null?void 0:x.general_settings)==null?void 0:k.language_code)||((D=(L=v.value)==null?void 0:L.general_settings)==null?void 0:D.language)||((B=(z=(T=u.value)==null?void 0:T.data)==null?void 0:z.franchisee)==null?void 0:B.language_code)||((V=(R=(E=u.value)==null?void 0:E.data)==null?void 0:R.franchisee)==null?void 0:V.language)||"en",a=String(e).toLowerCase();if(a==="en"||a==="english")return"en";const c=H.find(h=>h.code.toLowerCase()===a);if(c)return c.code.toLowerCase();const o=H.find(h=>h.name.toLowerCase()===a);return((W=o==null?void 0:o.code)==null?void 0:W.toLowerCase())||"en"}),O=n(()=>Array.isArray(y.value)?y.value:[]),g=n(()=>{var e,a;return((a=(e=u.value)==null?void 0:e.data)==null?void 0:a.role)==="super_admin"});n(()=>{var e,a;return["franchise_admin","franchise_editor"].includes((a=(e=u.value)==null?void 0:e.data)==null?void 0:a.role)});const U=e=>e?e.replace(/minutes?/gi,"min"):"-",I=[{field:"title",header:"Title",sortable:!0,style:{minWidth:"220px"},template:"user"},{field:"age_range",header:"Age",style:{minWidth:"120px"},template:"custom",customHTML:e=>`
      <div class="dt-table-cell">
        <i class="pi pi-users dt-table-cell__icon"></i>
        <span>${e.age_range}</span>
      </div>`},{field:"duration",header:"Duration",style:{minWidth:"120px"},template:"custom",customHTML:e=>`
      <div class="dt-table-cell">
        <i class="pi pi-clock dt-table-cell__icon"></i>
        <span>${U(e.duration)}</span>
      </div>`},{field:"status",header:"Status",sortable:!0,style:{minWidth:"120px"},template:"badge"},{field:"is_enabled",header:"Enabled",sortable:!0,style:{minWidth:"100px"},template:"toggle"}],j=[{icon:"pi pi-pencil",tooltip:"Edit Program",action:"edit",severity:"info",to:e=>`/programs/${e.id}/edit`},{icon:"pi pi-trash",tooltip:"Delete Program",action:"delete",severity:"danger",condition:e=>g.value||!e.is_global}],q=({action:e,rowData:a})=>{switch(e.action){case"edit":Y(a);break;case"delete":Z(a);break}},s=async()=>{!g.value&&!v.value&&await C.getSetting();const e=g.value?"en":N.value;await i.fetchProgramsLazy({page:t.value.page,rows:t.value.rows,sortField:t.value.sortField,sortOrder:t.value.sortOrder,search:t.value.search,language:e})},G=e=>{t.value.search=e,s()},J=()=>{t.value.search="",s()},K=()=>S.push("/programs/add"),Q=async({data:e})=>{try{await i.reorderPrograms(e)}catch{s()}},X=async e=>{if(f.value.has(e.id))return;const a=e.is_enabled;try{f.value.add(e.id),await i.updateProgram(e.id,{is_enabled:e.is_enabled}),await s()}catch{e.is_enabled=a}finally{f.value.delete(e.id)}},Y=e=>S.push(`/programs/${e.id}/edit`),Z=e=>{m.value=e,A.value="delete",d.value=!0},ee=async()=>{await i.deleteProgram(m.value.id),d.value=!1,s()};return se(s),re(s),(e,a)=>{var c;return $(),ne("div",fe,[p(me,{title:"Programs",subtitle:"Manage your programs and educational offerings",icon:"pi pi-graduation-cap"}),l("div",he,[l("div",_e,[l("div",be,[l("div",ye,[p(de,{modelValue:t.value.search,"onUpdate:modelValue":a[0]||(a[0]=o=>t.value.search=o),placeholder:"Search programs...",loading:b(w),size:"medium",onSearch:G,onClear:J},null,8,["modelValue","loading"])]),l("div",we,[g.value?($(),le(pe,{key:0,label:"New Program",icon:"pi pi-plus",severity:"primary",onClick:K})):ie("",!0)])]),l("div",Ce,[p(ge,{data:O.value,columns:I,actions:j,loading:b(w),"total-records":b(M),rows:t.value.rows,"rows-per-page-options":[10,25,50],lazy:!1,reorderable:!0,"data-key":"id",onReorder:Q,onToggleEnabled:X,onActionClick:q,onPage:a[1]||(a[1]=o=>{t.value.page=o.page+1,s()})},null,8,["data","loading","total-records","rows"])])])]),p(ue,{visible:d.value,"onUpdate:visible":a[2]||(a[2]=o=>d.value=o),title:A.value==="delete"?"Confirm Delete":"Confirm Action",message:`Delete '${(c=m.value)==null?void 0:c.title}'?`,item:m.value,onConfirm:ee,onCancel:a[3]||(a[3]=o=>d.value=!1)},null,8,["visible","title","message","item"])])}}},He=ve(Se,[["__scopeId","data-v-ce0751d4"]]);export{He as default};
