import{R as ce}from"./ReusableDataTable-1-hRJNZ3.js";import{S as de}from"./SearchBox-eFhvvd_1.js";import{H as ue}from"./HeroSection-D-Cp_ogz.js";import{A as ve}from"./ActionButton-6dFA985o.js";import{C as pe}from"./ConfirmationDialog-Dsr1A4w6.js";import{u as ge}from"./activityStore-Bw_vBJNT.js";import{z as $,y as me,T as fe,c as n,g as f,W as _e,ad as he,a as ye,o as B,d as h,e as c,u as y,p as Ae,b as be}from"./main-CJbVOHh0.js";import{u as Se}from"./settingStore-DBFwe1tS.js";import{u as xe}from"./useAppToast-CIos-t2x.js";import{l as V}from"./languageCode-D4o6NugM.js";import{_ as we}from"./_plugin-vue_export-helper-DlAUqK2U.js";/* empty css                                                                     */import"./cacheManager-C9fWw59Z.js";const Ce={class:"activity-page-container"},$e={class:"content-wrapper"},Le={class:"page-content"},ke={class:"toolbar"},Fe={class:"search-section"},De={class:"action-buttons"},Ne={class:"table-container"},Te={__name:"index",setup(ze){const d=ge(),{activities:L,total:E,loading:k,deleting:H,reordering:P}=$(d),U=me(),{user:_}=$(U),F=Se(),{setting:A}=$(F),D=fe(),{success:b,error:S}=xe(),I=n(()=>{var o,v,p,g,m,T,z,M,O,R,W;const e=((v=(o=A.value)==null?void 0:o.general_settings)==null?void 0:v.language_code)||((g=(p=A.value)==null?void 0:p.general_settings)==null?void 0:g.language)||((z=(T=(m=_.value)==null?void 0:m.data)==null?void 0:T.franchisee)==null?void 0:z.language_code)||((R=(O=(M=_.value)==null?void 0:M.data)==null?void 0:O.franchisee)==null?void 0:R.language)||"en",t=String(e).toLowerCase();if(t==="en"||t==="english")return"en";const i=V.find(C=>C.code.toLowerCase()===t);if(i)return i.code.toLowerCase();const s=V.find(C=>C.name.toLowerCase()===t);return((W=s==null?void 0:s.code)==null?void 0:W.toLowerCase())||"en"}),G=n(()=>Array.isArray(L.value)?L.value:[]),a=f({page:1,rows:50,sortField:"order_no",sortOrder:1,search:""}),N=f([]),u=f(!1),l=f(null);n(()=>N.value.map(e=>e.id)),n(()=>N.value.length>0);const x=n(()=>{var e,t;return((t=(e=_.value)==null?void 0:e.data)==null?void 0:t.role)==="super_admin"}),j=n(()=>{var e,t;return["franchise_admin","franchise_editor"].includes((t=(e=_.value)==null?void 0:e.data)==null?void 0:t.role)}),q=(e,t)=>{var i;return e&&(e[t]||((i=e.activity_details)==null?void 0:i[t]))||"N/A"},J=e=>{var v,p,g,m;if(!e)return"N/A";const t=e.age||((v=e.activity_details)==null?void 0:v.age),i=e.age_text||((p=e.activity_details)==null?void 0:p.age_text)||"Age",s=e.grade||((g=e.activity_details)==null?void 0:g.grade),o=e.grade_text||((m=e.activity_details)==null?void 0:m.grade_text)||"Grade";return t?`${t} ${i}`.trim():s?`${s} ${o}`.trim():"N/A"},K=e=>{var s,o;if(!e)return"N/A";const t=e.duration||((s=e.activity_details)==null?void 0:s.duration),i=e.duration_text||((o=e.activity_details)==null?void 0:o.duration_text)||"";return t?`${t} ${i}`.trim():"N/A"},Q=[{field:"title",header:"Activity Name",sortable:!0,style:{minWidth:"250px"},template:"user"},{field:"audience",header:"Audience",style:{minWidth:"140px"},template:"custom",customHTML:e=>`
      <div class="dt-table-cell">
        <i class="pi pi-users dt-table-cell__icon"></i>
        <span>${J(e)}</span>
      </div>
    `},{field:"duration",header:"Duration",style:{minWidth:"140px"},template:"custom",customHTML:e=>`
      <div class="dt-table-cell">
        <i class="pi pi-clock dt-table-cell__icon"></i>
        <span>${K(e)}</span>
      </div>
    `},{field:"created_for",header:"Created For",style:{minWidth:"150px"},template:"custom",customHTML:e=>`
      <div class="dt-table-cell">
        <i class="pi pi-building dt-table-cell__icon"></i>
        <span>${q(e,"created_for")}</span>
      </div>
    `},{field:"status",header:"Status",sortable:!0,style:{minWidth:"120px"},template:"badge"},{field:"is_enabled",header:"Enabled",sortable:!0,style:{minWidth:"110px"},template:"toggle"}],X=[{icon:"pi pi-pencil",tooltip:"Edit Activity",severity:"info",action:"edit",to:e=>`/activity/${e.id}/edit`},{icon:"pi pi-trash",tooltip:"Delete Activity",severity:"danger",action:"delete",show:e=>!(j.value&&e.is_global===!0)}],Y=({action:e,rowData:t})=>{switch(e.action){case"edit":oe(t);break;case"delete":le(t);break}},r=async()=>{try{!x.value&&!A.value&&await F.getSetting();const e=x.value?"en":I.value;await d.fetchActivitiesLazy({page:a.value.page,rows:a.value.rows,sortField:a.value.sortField,sortOrder:a.value.sortOrder,search:a.value.search,language:e})}catch(e){console.error("Load activities error:",e)}},Z=e=>{a.value.page=e.page+1,a.value.rows=e.rows,r()},ee=e=>{a.value.sortField=e.sortField,a.value.sortOrder=e.sortOrder,r()},te=e=>{a.value.search=e,a.value.page=1,r()},ae=()=>{a.value.search="",a.value.page=1,r()},w=f(new Set),ie=async e=>{if(w.value.has(e.id))return;const t=!!e.is_enabled,i=!t;try{w.value.add(e.id),await d.updateActivity(e.id,{is_enabled:t}),b(`Activity ${t?"enabled":"disabled"} successfully`)}catch(s){console.error("Toggle status error:",s),e.is_enabled=i,S("Failed to update activity enabled state")}finally{w.value.delete(e.id)}},se=async({data:e})=>{if(P.value||!Array.isArray(e)||!e.length)return;const t=e.map((i,s)=>({...i,order_no:s+1}));try{await d.reorderActivities(t),b("Activity order updated")}catch(i){console.error("Reorder error:",i),S("Failed to update activity order"),await r()}},re=()=>{D.push("/activity/add")},oe=e=>{D.push(`/activity/${e.id}/edit`)},le=e=>{l.value=e,u.value=!0},ne=async()=>{if(l.value)try{const e=await d.deleteActivity(l.value.id);e&&e.success!==!1&&(u.value=!1,l.value=null,await r(),b("Activity deleted"))}catch(e){console.error("Delete error:",e),S("Failed to delete")}};return _e(()=>{r()}),he(()=>{r()}),(e,t)=>{var i;return B(),ye("div",Ce,[h(ue,{title:"Activity Manager",subtitle:"Manage your curriculum activities and lessons",icon:"pi pi-book"}),c("div",$e,[c("div",Le,[c("div",ke,[c("div",Fe,[h(de,{modelValue:a.value.search,"onUpdate:modelValue":t[0]||(t[0]=s=>a.value.search=s),placeholder:"Search activities...",loading:y(k),size:"medium",onSearch:te,onClear:ae,class:"w-full"},null,8,["modelValue","loading"])]),c("div",De,[x.value?(B(),Ae(ve,{key:0,label:"Add New Activity",icon:"pi pi-plus",severity:"primary",onClick:re})):be("",!0)])]),c("div",Ne,[h(ce,{data:G.value,columns:Q,actions:X,loading:y(k),"total-records":y(E),rows:a.value.rows,"sort-field":a.value.sortField,"sort-order":a.value.sortOrder,lazy:!1,paginator:!0,"rows-per-page-options":[10,25,50],"data-key":"id","table-class":"activities-table",reorderable:!0,onPage:Z,onSort:ee,onActionClick:Y,onToggleEnabled:ie,onReorder:se},null,8,["data","loading","total-records","rows","sort-field","sort-order"])])])]),h(pe,{visible:u.value,"onUpdate:visible":t[1]||(t[1]=s=>u.value=s),title:"Delete Activity",message:`Are you sure you want to delete '${(i=l.value)==null?void 0:i.title}'?`,item:l.value,loading:y(H),onConfirm:ne,onCancel:t[2]||(t[2]=()=>u.value=!1)},null,8,["visible","message","item","loading"])])}}},qe=we(Te,[["__scopeId","data-v-6627d1ab"]]);export{qe as default};
