"use strict";(globalThis["webpackChunkbaggisowtfaresystem"]=globalThis["webpackChunkbaggisowtfaresystem"]||[]).push([[548],{4548:(e,l,a)=>{a.r(l),a.d(l,{default:()=>q});a(939),a(7008),a(4520),a(7049);var o=a(1347),t=a(4187),s=a(7763),n=a(144),u=a(2986),d=a(588);const i={class:"row q-col-gutter-md q-mb-md"},m={class:"col-4"},r={class:"col-4"},c={key:0},p={class:"q-mt-md"},v={__name:"PermissionMatrix",async setup(e){let l,a;const{canRead:v,canUpdate:k}=(0,d.J)(),y=v("system"),b=k("user"),g=(0,t.KR)([]),f=(0,t.KR)([]),w=(0,t.KR)(null),h=(0,t.KR)(null),A=(0,t.KR)([]),R=(0,t.KR)(!1),q=(0,t.KR)(!1),V=[{key:"write",label:"Ekleme"},{key:"read",label:"Görüntüleme"},{key:"delete",label:"Silme"},{key:"update",label:"Güncelleme"},{key:"export",label:"Çıktı"}],[K,x,_]=([l,a]=(0,o.E)(()=>Promise.all([u.Ay.get("/lookups/roles"),u.Ay.get("/lookups/departments"),u.Ay.get("/lookups/modules")])),l=await l,a(),l);modules.value=_.data||[];const E=[{name:"module",label:"Modül",field:"label",align:"left"},...V.map(e=>({name:e.key,label:e.label,align:"center"}))];async function L(){const[e,l]=await Promise.all([u.Ay.get("/lookups/roles"),u.Ay.get("/lookups/departments")]);g.value=e.data,f.value=l.data}function Q(){A.value=modules.map(e=>{const l={module:e.code,label:e.label};return V.forEach(e=>{l[e.key]=!1}),l})}async function C(){if(w.value&&h.value){R.value=!0;try{Q();await u.Ay.get(`/roles/${w.value}/departments/${h.value}/permissions`);list.forEach(e=>{const l=String(e.module_code||e.module).toLowerCase().trim(),a=A.value.find(e=>e.module===l);a&&(a[e.action]=e.allowed)}),q.value=!1}catch{n.A.create({type:"negative",message:"Yetkiler yüklenemedi"})}finally{R.value=!1}}}async function U(){try{R.value=!0;const e=[];A.value.forEach(l=>{V.forEach(a=>{e.push({module:l.module,action:a.key,allowed:l[a.key]})})}),await u.Ay.post(`/roles/${w.value}/departments/${h.value}/permissions`,e),n.A.create({type:"positive",message:"Kaydedildi"}),q.value=!1}catch{n.A.create({type:"negative",message:"Kayıt hatası"})}finally{R.value=!1}}return(0,o.sV)(()=>{L()}),(e,l)=>{const a=(0,o.g2)("q-select"),n=(0,o.g2)("q-checkbox"),u=(0,o.g2)("q-td"),d=(0,o.g2)("q-table"),v=(0,o.g2)("q-btn"),k=(0,o.g2)("q-page");return(0,t.R1)(y)?((0,o.uX)(),(0,o.Wv)(k,{key:0,padding:""},{default:(0,o.k6)(()=>[l[3]||(l[3]=(0,o.Lk)("div",{class:"text-h6 q-mb-md"}," Rol + Departman Yetkilendirme ",-1)),(0,o.Lk)("div",i,[(0,o.Lk)("div",m,[(0,o.bF)(a,{modelValue:w.value,"onUpdate:modelValue":[l[0]||(l[0]=e=>w.value=e),C],options:g.value,label:"Rol",dense:"",outlined:"","emit-value":"","map-options":""},null,8,["modelValue","options"])]),(0,o.Lk)("div",r,[(0,o.bF)(a,{modelValue:h.value,"onUpdate:modelValue":[l[1]||(l[1]=e=>h.value=e),C],options:f.value,label:"Departman",dense:"",outlined:"","emit-value":"","map-options":""},null,8,["modelValue","options"])])]),(0,o.bF)(d,{rows:A.value,columns:E,"row-key":"module",flat:"",bordered:"",dense:"",loading:R.value},{"body-cell":(0,o.k6)(e=>[(0,o.bF)(u,{props:e},{default:(0,o.k6)(()=>["module"===e.col.name?((0,o.uX)(),(0,o.CE)("span",c,(0,s.v_)(e.row.label),1)):((0,o.uX)(),(0,o.Wv)(n,{key:1,modelValue:e.row[e.col.name],"onUpdate:modelValue":[l=>e.row[e.col.name]=l,l[2]||(l[2]=e=>q.value=!0)],dense:""},null,8,["modelValue","onUpdate:modelValue"]))]),_:2},1032,["props"])]),_:1},8,["rows","loading"]),(0,o.Lk)("div",p,[(0,t.R1)(b)?((0,o.uX)(),(0,o.Wv)(v,{key:0,color:"primary",icon:"save",label:"Kaydet",disable:!q.value,onClick:U},null,8,["disable"])):(0,o.Q3)("",!0)])]),_:1})):((0,o.uX)(),(0,o.Wv)(k,{key:1,class:"q-pa-md flex flex-center"},{default:(0,o.k6)(()=>[...l[4]||(l[4]=[(0,o.Lk)("div",{class:"text-negative text-subtitle1"}," Bu module erisim yetkiniz yok. ",-1)])]),_:1}))}}};var k=a(5013),y=a(6941),b=a(6087),g=a(8785),f=a(8349),w=a(2677),h=a(272),A=a.n(h);const R=v,q=R;A()(v,"components",{QPage:k.A,QSelect:y.A,QTable:b.A,QTd:g.A,QCheckbox:f.A,QBtn:w.A})}}]);