import{R as P}from"./ReusableDataTable-1-hRJNZ3.js";import{S as U}from"./SearchBox-eFhvvd_1.js";import{A as $}from"./ActionButton-6dFA985o.js";import{C as E}from"./ConfirmationDialog-Dsr1A4w6.js";import{H}from"./HeroSection-D-Cp_ogz.js";import{T as j,z as g,y as I,g as m,c as _,W as L,a as M,o as b,d as c,e as r,u as i,p as Y,b as q,ab as p}from"./main-CJbVOHh0.js";import{u as G}from"./formStore-D-rCXtNc.js";import{_ as J}from"./_plugin-vue_export-helper-DlAUqK2U.js";/* empty css                                                                     */import"./cacheManager-C9fWw59Z.js";const K={class:"forms-page-container"},Q={class:"content-wrapper"},X={class:"page-content"},Z={class:"toolbar"},ee={class:"search-section"},oe={class:"action-buttons"},te={class:"table-container"},ae={__name:"index",setup(se){const f=j(),d=G(),{forms:y,total:F,loading:v,deleting:S}=g(d),w=I(),{user:C}=g(w),o=m({page:1,rows:10,sortField:"",sortOrder:0,search:""}),s=m(!1),a=m(null),n=_(()=>{var e,t;return((t=(e=C.value)==null?void 0:e.data)==null?void 0:t.role)==="super_admin"}),x=[{field:"name",header:"Form Name",sortable:!0,style:{minWidth:"250px"},template:"user"},{field:"status",header:"Status",sortable:!0,template:"badge",style:{minWidth:"120px"}},{field:"created_at",header:"Created",sortable:!0,style:{minWidth:"150px"},type:"datetime"}],A=[{icon:"pi pi-pencil",tooltip:"Edit Form",severity:"info",action:"edit",to:e=>`/forms/edit/${e.id}`},{icon:"pi pi-trash",tooltip:"Delete Form",severity:"danger",action:"delete",show:e=>n.value||!e.is_global&&!!e.franchisee_id}],k=_(()=>A),l=async()=>{await d.fetchFormsLazy(o.value)},z=e=>{o.value.page=e.page+1,o.value.rows=e.rows,l()},B=e=>{o.value.sortField=e.sortField,o.value.sortOrder=e.sortOrder,l()},D=e=>{o.value.search=e,o.value.page=1,l()},T=()=>{o.value.search="",o.value.page=1,l()},V=()=>{n.value&&f.push("/forms/add")},N=e=>{f.push(`/forms/edit/${e.id}`)},O=e=>{a.value=e,s.value=!0},R=async()=>{if(a.value)try{const e=await d.deleteForm(a.value.id);e&&e.success?(s.value=!1,a.value=null):p("error","",(e==null?void 0:e.error)||"Failed to delete form")}catch(e){console.error("Delete error:",e),p("error","","Failed to delete form"),e.message&&e.message.includes("Toast service not initialized")&&(s.value=!1,a.value=null)}},W=({action:e,rowData:t})=>{if(e.action==="delete"){if(!n.value&&t.is_global){p("error","","You cannot delete global forms");return}O(t);return}e.action==="edit"&&N(t)};return L(async()=>{l()}),(e,t)=>{var h;return b(),M("div",K,[c(H,{title:"Forms",subtitle:"Create and manage dynamic forms for your applications",icon:"pi pi-align-justify"}),r("div",Q,[r("div",X,[r("div",Z,[r("div",ee,[c(U,{modelValue:o.value.search,"onUpdate:modelValue":t[0]||(t[0]=u=>o.value.search=u),placeholder:"Search forms...",loading:i(v),size:"medium",onSearch:D,onClear:T,class:"w-full"},null,8,["modelValue","loading"])]),r("div",oe,[n.value?(b(),Y($,{key:0,label:"New Form",icon:"pi pi-plus",class:"create-button",onClick:V})):q("",!0)])]),r("div",te,[c(P,{data:i(y),columns:x,actions:k.value,loading:i(v),"total-records":i(F),rows:o.value.rows,"sort-field":o.value.sortField,"sort-order":o.value.sortOrder,lazy:!0,paginator:!0,"rows-per-page-options":[10,25,50],"data-key":"id",onPage:z,onSort:B,onActionClick:W},null,8,["data","actions","loading","total-records","rows","sort-field","sort-order"])])])]),c(E,{visible:s.value,"onUpdate:visible":t[1]||(t[1]=u=>s.value=u),title:"Delete Form",message:`Are you sure you want to delete '${(h=a.value)==null?void 0:h.name}'? This action cannot be undone.`,item:a.value,loading:i(S),onConfirm:R,onCancel:t[2]||(t[2]=()=>s.value=!1)},null,8,["visible","message","item","loading"])])}}},ve=J(ae,[["__scopeId","data-v-84abef5a"]]);export{ve as default};
