import{f as C,d as A,az as k,r as o,j as e,v as i,I as u,B as w,bj as T}from"./index-Db-xuq0b.js";import{C as z,a as E,b as M,d as B}from"./card-BBWyxDss.js";import{L as t}from"./label-CsFy6wpo.js";import{S as O,a as V,b as F,c as H,d as K}from"./select-BoQxM42A.js";import{u as U}from"./useUnit-C4s9nepK.js";import{u as q,P as D,p as G}from"./useApplications-DVlMarnX.js";import{u as J}from"./usePositionTypes-BW1bd5Uk.js";import"./unitService-CmGVtFHQ.js";import"./checkbox-Dd0VhnrO.js";import"./Checkbox-IILksgz0.js";import"./get-auto-contrast-value-Da6zqqWm.js";import"./InputsGroupFieldset-COkNgcEo.js";import"./use-uncontrolled-C3HRHW6t.js";import"./form-BeLK5rTt.js";import"./index.esm-BG4gweZJ.js";import"./search-CM5F2ZRy.js";const Q=({id:r})=>{var h,j;const y=C(),{user:n}=A(),{getList:v}=U(),x=k(),{positionType:a,isLoadingSingle:f}=J({id:r}),N=n!=null&&n.employee&&n.employee.length>0?n.employee[0].organizationId:void 0,{applications:d,isLoading:P}=q(),{data:l}=v(N||"",{take:300,skip:0}),[c,b]=o.useState(""),[m,S]=o.useState([]),[I,g]=o.useState(!1);if(o.useEffect(()=>{(async()=>{if(a){g(!0);try{const L=await G.getPermissionsByPositionTypeId(a.id);S(L.data.items??[])}finally{g(!1)}}})()},[a]),f)return e.jsx("p",{children:"Loading..."});if(!a)return null;const p=(j=(h=l==null?void 0:l.data)==null?void 0:h.items)==null?void 0:j.find(s=>s.id===a.unitId);return p?p.name.en||p.name.am:a.unitId,e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t,{children:i("contentManagement.englishName")}),e.jsx(u,{value:a.name.en,disabled:!0,readOnly:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t,{children:i("contentManagement.amharicName")}),e.jsx(u,{value:a.name.am,disabled:!0,readOnly:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t,{children:"Key"}),e.jsx(u,{value:a.key,disabled:!0,readOnly:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t,{children:i("contentManagement.selectApplication")}),e.jsxs(O,{value:c,onValueChange:s=>b(s),disabled:P,children:[e.jsx(V,{className:"mt-1 block w-full border-gray-300 rounded-md shadow-sm",children:e.jsx(F,{placeholder:"Select an Application"})}),e.jsx(H,{className:"max-h-60 overflow-y-auto",children:d==null?void 0:d?.map(s=>e.jsx(K,{value:s.id,children:x(s.name)},s.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t,{children:i("contentManagement.permission")}),c?e.jsx(D,{selectedPermissions:m?.map(s=>s.id),onPermissionChange:()=>{},applicationId:c,disabled:!0}):e.jsx("div",{className:"border rounded-md p-4 bg-background max-h-96 overflow-y-auto",children:I?e.jsx("div",{className:"text-center py-4 text-gray-500",children:"Loading..."}):m.length===0?e.jsx("div",{className:"text-center py-4 text-gray-500",children:i("contentManagement.noPermissionsAvailable")}):e.jsx("ul",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:m?.map(s=>e.jsx("li",{className:"capitalize text-sm py-1 px-2 rounded bg-muted/40",children:x(s.name)},s.id))})})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(w,{type:"button",variant:"outline",onClick:()=>y("/user-management/position-management"),children:i("common.Back")})})]})},le=()=>{const{id:r}=T();return e.jsx("div",{className:"p-6 max-w-3xl mx-auto",children:e.jsxs(z,{children:[e.jsx(E,{children:e.jsx(M,{children:"View Permission Type"})}),e.jsx(B,{children:e.jsx(Q,{id:r})})]})})};export{le as default};
