"use strict";(globalThis["webpackChunkbaggisowtfaresystem"]=globalThis["webpackChunkbaggisowtfaresystem"]||[]).push([[465],{4465:(e,l,a)=>{a.r(l),a.d(l,{default:()=>_});a(939),a(3872),a(7008),a(4520),a(7049);var o=a(1347),t=a(4187),s=a(7763),n=a(144),u=a(2986),r=a(588);const i={key:0,class:"q-pa-xl flex flex-center"},c={class:"sticky-stack"},d={key:0,class:"filter-bar row q-col-gutter-md"},m={class:"col-4"},v={class:"save-toolbar"},p={key:0,class:"permissions-table-scroll"},k={key:0},y={key:1,class:"column items-center"},b={class:"text-caption"},g={key:0},f={__name:"UserPermissionPage",setup(e){const{canUpdate:l}=(0,r.J)(),a=l("user"),f=(0,t.KR)([]),w=(0,t.KR)(null),h=(0,t.KR)([]),A=(0,t.KR)([]),E=(0,t.KR)(!1),x=(0,t.KR)(!1),C=(0,t.KR)(!1),R=[{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=[{name:"module",label:"Modül",field:"label",align:"left"},...R.map(e=>({name:e.key,label:e.label,align:"center"}))];async function Q(){const[e,l]=await Promise.all([u.Ay.get("/lookups/users-perm"),u.Ay.get("/lookups/modules")]);f.value=e.data||[],h.value=l.data||[],C.value=!0}function q(){A.value=h.value.map(e=>{const l={module:String(e.value).toLowerCase().trim(),label:e.label};return R.forEach(e=>{l[e.key]=!1}),l})}async function X(){if(w.value){E.value=!0;try{q();const e=await u.Ay.get(`/users/${w.value}/permissions`),l=Array.isArray(e.data)?e.data:[],a={insert:"write",view:"read",delete:"delete",update:"update",export:"export"};l.forEach(e=>{const l=String(e.module_code||e.module).toLowerCase().trim(),o=String(e.action).toLowerCase().trim(),t=a[o]||o,s=A.value.find(e=>e.module===l);s&&s.hasOwnProperty(t)&&(s[t]=Boolean(e.allowed))}),x.value=!1}catch(e){console.error("PERM LOAD ERROR:",e),n.A.create({type:"negative",message:"Yükleme hatası"})}finally{E.value=!1}}}async function _(){try{E.value=!0;const e=[];A.value.forEach(l=>{R.forEach(a=>{e.push({module:l.module,action:a.key,allowed:l[a.key]})})}),await u.Ay.post(`/users/${w.value}/permissions`,e),n.A.create({type:"positive",message:"Kaydedildi"}),x.value=!1}catch{n.A.create({type:"negative",message:"Kayıt hatası"})}finally{E.value=!1}}function L(e){return!!A.value.length&&A.value.every(l=>!0===l[e])}function V(e,l){A.value.forEach(a=>{a[e]=l}),x.value=!0}return(0,o.sV)(()=>{Q()}),(e,l)=>{const n=(0,o.g2)("q-spinner"),u=(0,o.g2)("q-select"),r=(0,o.g2)("q-btn"),h=(0,o.g2)("q-checkbox"),R=(0,o.g2)("q-th"),Q=(0,o.g2)("q-td"),q=(0,o.g2)("q-table"),P=(0,o.g2)("q-page");return(0,o.uX)(),(0,o.CE)(o.FK,null,[(0,t.R1)(a)&&!C.value?((0,o.uX)(),(0,o.CE)("div",i,[(0,o.bF)(n,{color:"primary",size:"48px"})])):(0,o.Q3)("",!0),(0,t.R1)(a)?((0,o.uX)(),(0,o.Wv)(P,{key:1,class:"permissions-page"},{default:(0,o.k6)(()=>[(0,o.Lk)("div",c,[C.value?((0,o.uX)(),(0,o.CE)("div",d,[(0,o.Lk)("div",m,[(0,o.bF)(u,{modelValue:w.value,"onUpdate:modelValue":[l[0]||(l[0]=e=>w.value=e),X],options:f.value,"option-value":"id","option-label":"title","emit-value":"","map-options":"",label:"Kullanıcı",dense:"",outlined:""},null,8,["modelValue","options"])])])):(0,o.Q3)("",!0),(0,o.Lk)("div",v,[l[2]||(l[2]=(0,o.Lk)("div",{class:"label"}," Kullanıcı Override Yetkileri ",-1)),(0,t.R1)(a)?((0,o.uX)(),(0,o.Wv)(r,{key:0,color:"primary",icon:"save",label:"Kaydet",disable:!x.value,onClick:_},null,8,["disable"])):(0,o.Q3)("",!0)])]),C.value?((0,o.uX)(),(0,o.CE)("div",p,[(0,o.bF)(q,{rows:A.value,columns:K,"row-key":"module",dense:"",bordered:"",flat:"",loading:E.value,pagination:{rowsPerPage:0}},{"header-cell":(0,o.k6)(e=>[(0,o.bF)(R,{props:e},{default:(0,o.k6)(()=>["module"===e.col.name?((0,o.uX)(),(0,o.CE)("span",k,(0,s.v_)(e.col.label),1)):((0,o.uX)(),(0,o.CE)("div",y,[(0,o.Lk)("span",b,(0,s.v_)(e.col.label),1),(0,o.bF)(h,{dense:"","model-value":L(e.col.name),"onUpdate:modelValue":l=>V(e.col.name,l)},null,8,["model-value","onUpdate:modelValue"])]))]),_:2},1032,["props"])]),"body-cell":(0,o.k6)(e=>[(0,o.bF)(Q,{props:e},{default:(0,o.k6)(()=>["module"===e.col.name?((0,o.uX)(),(0,o.CE)("span",g,(0,s.v_)(e.row.label),1)):((0,o.uX)(),(0,o.Wv)(h,{key:1,modelValue:e.row[e.col.name],"onUpdate:modelValue":[l=>e.row[e.col.name]=l,l[1]||(l[1]=e=>x.value=!0)],dense:""},null,8,["modelValue","onUpdate:modelValue"]))]),_:2},1032,["props"])]),_:1},8,["rows","loading"])])):(0,o.Q3)("",!0)]),_:1})):((0,o.uX)(),(0,o.Wv)(P,{key:2,class:"q-pa-md flex flex-center"},{default:(0,o.k6)(()=>[...l[3]||(l[3]=[(0,o.Lk)("div",{class:"text-negative text-subtitle1"}," Bu module erisim yetkiniz yok. ",-1)])]),_:1}))],64)}}};var w=a(6356),h=a(5013),A=a(6941),E=a(2677),x=a(6087),C=a(2517),R=a(8349),K=a(8785),Q=a(272),q=a.n(Q);const X=f,_=X;q()(f,"components",{QSpinner:w.A,QPage:h.A,QSelect:A.A,QBtn:E.A,QTable:x.A,QTh:C.A,QCheckbox:R.A,QTd:K.A})}}]);