import{r as e,t}from"./jsx-runtime-DAs1UGHr.js";import{t as n}from"./react-DxF41JXl.js";import{j as r}from"./use-api-BAbm8GVs.js";import{n as i,r as a}from"./use-toast-CpnYXdO8.js";var o=e(n(),1),s=e(t(),1);const c=({label:e,error:t,options:n,className:r=``,containerClassName:i=``,id:a,ref:o,reserveErrorSpace:c=!1,...l})=>{let u=t||(c?`\xA0`:null);return(0,s.jsxs)(`div`,{className:i,children:[e&&(0,s.jsxs)(`label`,{htmlFor:a,className:`block text-sm font-medium text-text-primary dark:text-text-primary-dark mb-1`,children:[e,l.required&&`*`]}),(0,s.jsx)(`select`,{ref:o,id:a,className:`w-full px-3 py-2 border rounded-md focus:outline-none 
            text-ui-text dark:text-ui-text-dark
            bg-ui-bg dark:bg-ui-bg-dark
            border-ui-border dark:border-ui-border-dark
            focus:border-btn-primary dark:focus:border-btn-primary-dark
            transition duration-150 ease-in-out cursor-pointer
            disabled:opacity-70 disabled:cursor-not-allowed
            ${t?`border-red-500 focus:border-red-500 dark:border-red-500 dark:focus:border-red-500`:``}
            ${r}`,...l,children:n.map(e=>{let t=typeof e==`string`?e:e.label,n=typeof e==`string`?e:e.value;return(0,s.jsx)(`option`,{value:n,children:t},n)})}),u&&(0,s.jsx)(`p`,{className:`mt-1 text-sm ${t?`text-red-500`:`invisible`}`,children:u})]})};c.displayName=`Select`;var l=[`READ`,`EDIT`,`MANAGE`,`NO_PERMISSIONS`];const u=({isOpen:e,onClose:t,onSave:n,item:u,username:d,resourceId:f,type:p,isLoading:m=!1})=>{let[h,g]=(0,o.useState)(u?.permission||`READ`),[_,v]=(0,o.useState)(u&&`regex`in u?u.regex:``),[y,b]=(0,o.useState)(u&&`priority`in u?u.priority:0);if((0,o.useEffect)(()=>{e&&u&&(g(u.permission),`regex`in u&&(v(u.regex),b(u.priority)))},[e,u]),!e||!u)return null;let x=async()=>{`regex`in u?await n(h,_,y):await n(h)},S=`regex`in u,C=`name`in u?u.name:u.regex,w=f||C;return(0,s.jsxs)(a,{isOpen:e,onClose:t,title:S?`Manage Regex Rule ${C}`:`Edit ${p.charAt(0).toUpperCase()+p.slice(1,-1)} ${w} permissions for ${d}`,children:[S&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i,{id:`regex-pattern`,label:`Regex Pattern`,type:`text`,value:_,onChange:e=>v(e.target.value),className:`opacity-70 cursor-not-allowed`,required:!0,readOnly:!0,containerClassName:`mb-4`}),(0,s.jsx)(i,{id:`priority`,label:`Priority`,type:`number`,value:y,onChange:e=>b(parseInt(e.target.value,10)),required:!0,containerClassName:`mb-4`})]}),(0,s.jsx)(c,{id:`permission-level`,label:`Permission Level`,value:h,onChange:e=>g(e.target.value),options:l.map(e=>({label:e,value:e})),containerClassName:`mb-4`}),(0,s.jsxs)(`div`,{className:`flex justify-end space-x-3`,children:[(0,s.jsx)(r,{onClick:t,variant:`ghost`,disabled:m,children:`Cancel`}),(0,s.jsx)(r,{onClick:()=>{x()},variant:`primary`,disabled:m,children:m?`Saving...`:`Ok`})]})]})};var d=[`READ`,`EDIT`,`MANAGE`,`NO_PERMISSIONS`];const f=({isOpen:e,onClose:t,onSave:n,title:i,label:l,options:u,isLoading:f=!1})=>{let[p,m]=(0,o.useState)(``),[h,g]=(0,o.useState)(`READ`);(0,o.useEffect)(()=>{e&&(m(``),g(`READ`))},[e]);let _=async()=>{p&&await n(p,h)};return(0,s.jsxs)(a,{isOpen:e,onClose:t,title:i,children:[(0,s.jsx)(c,{id:`username-select`,label:l,value:p,onChange:e=>m(e.target.value),required:!0,options:[{label:`Select ${l.toLowerCase()}...`,value:``},...u].map(e=>typeof e==`string`?{label:e,value:e}:e),containerClassName:`mb-4`}),(0,s.jsx)(c,{id:`permission-level`,label:`Permissions`,value:h,onChange:e=>g(e.target.value),required:!0,options:d.map(e=>({label:e,value:e})),containerClassName:`mb-4`}),(0,s.jsxs)(`div`,{className:`flex justify-end space-x-3`,children:[(0,s.jsx)(r,{onClick:t,variant:`ghost`,disabled:f,children:`Cancel`}),(0,s.jsx)(r,{onClick:()=>{_()},variant:`primary`,disabled:f||!p,children:f?`Saving...`:`Save`})]})]})};export{u as n,c as r,f as t};