import{i as e,o as t,r as n,t as r}from"./button-DJ30HgDO.js";import{n as i}from"./use-toast-ehNQGp1o.js";import{t as a}from"./input-C5ngh159.js";import{n as o}from"./grant-permission-modal-C0plkvS4.js";var s=t(e(),1),c=t(n(),1);const l=({isOpen:e,onClose:t,onSave:n,item:l,username:u,resourceId:d,type:f,isLoading:p=!1})=>{let[m,h]=(0,s.useState)(l?.permission||`READ`),[g,_]=(0,s.useState)(l&&`regex`in l?l.regex:``),[v,y]=(0,s.useState)(l&&`priority`in l?l.priority:0);if(!e||!l)return null;let b=async()=>{`regex`in l?await n(m,g,v):await n(m)},x=`regex`in l,S=`name`in l?l.name:l.regex,C=d||S;return(0,c.jsxs)(i,{isOpen:e,onClose:t,title:x?`Manage Regex Rule ${S}`:`Edit ${f.charAt(0).toUpperCase()+f.slice(1,-1)} ${C} permissions for ${u}`,children:[x&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a,{id:`regex-pattern`,label:`Regex Pattern`,type:`text`,value:g,onChange:e=>_(e.target.value),className:`opacity-70 cursor-not-allowed`,required:!0,readOnly:!0,containerClassName:`mb-4`}),(0,c.jsx)(a,{id:`priority`,label:`Priority`,type:`number`,value:v,onChange:e=>y(parseInt(e.target.value,10)),required:!0,containerClassName:`mb-4`})]}),(0,c.jsx)(o,{id:`permission-level`,label:`Permission Level`,value:m,onChange:e=>h(e),type:f,containerClassName:`mb-4`}),(0,c.jsxs)(`div`,{className:`flex justify-end space-x-3`,children:[(0,c.jsx)(r,{onClick:t,variant:`ghost`,disabled:p,children:`Cancel`}),(0,c.jsx)(r,{onClick:()=>{b()},variant:`primary`,disabled:p,children:p?`Saving...`:`Ok`})]})]})};export{l as t};