import{i as e,o as t,r as n,t as r}from"./button-DJ30HgDO.js";import{n as i}from"./use-toast-BWmLhWRD.js";import{t as a}from"./input-BbiN5lj4.js";var o=t(e(),1),s=t(n(),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
            custom-select
            ${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`],u=[`READ`,`USE`,`EDIT`,`MANAGE`,`NO_PERMISSIONS`];const d=({value:e,onChange:t,type:n,id:r=`permission-level`,label:i=`Permissions*`,disabled:a=!1,required:o=!0,className:d,containerClassName:f})=>(0,s.jsx)(c,{id:r,label:i,value:e,onChange:e=>t(e.target.value),required:o,disabled:a,options:(n===`ai-endpoints`||n===`ai-secrets`||n===`ai-models`?u:l).map(e=>({label:e,value:e})),className:d,containerClassName:f}),f=({isOpen:e,onClose:t,onSave:n,item:c,username:l,resourceId:u,type:f,isLoading:p=!1})=>{let[m,h]=(0,o.useState)(c?.permission||`READ`),[g,_]=(0,o.useState)(c&&`regex`in c?c.regex:``),[v,y]=(0,o.useState)(c&&`priority`in c?c.priority:0);if(!e||!c)return null;let b=async()=>{`regex`in c?await n(m,g,v):await n(m)},x=`regex`in c,S=`name`in c?c.name:c.regex,C=u||S;return(0,s.jsxs)(i,{isOpen:e,onClose:t,title:x?`Manage Regex Rule ${S}`:`Edit ${f.charAt(0).toUpperCase()+f.slice(1,-1)} ${C} permissions for ${l}`,children:[x&&(0,s.jsxs)(s.Fragment,{children:[(0,s.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,s.jsx)(a,{id:`priority`,label:`Priority`,type:`number`,value:v,onChange:e=>y(parseInt(e.target.value,10)),required:!0,containerClassName:`mb-4`})]}),(0,s.jsx)(d,{id:`permission-level`,label:`Permission Level`,value:m,onChange:e=>h(e),type:f,containerClassName:`mb-4`}),(0,s.jsxs)(`div`,{className:`flex justify-end space-x-3`,children:[(0,s.jsx)(r,{onClick:t,variant:`ghost`,disabled:p,children:`Cancel`}),(0,s.jsx)(r,{onClick:()=>{b()},variant:`primary`,disabled:p,children:p?`Saving...`:`Ok`})]})]})},p=({isOpen:e,onClose:t,onSave:n,title:a,label:l,options:u,type:f,isLoading:p=!1})=>{let[m,h]=(0,o.useState)(``),[g,_]=(0,o.useState)(`READ`),v=async()=>{m&&await n(m,g)};return(0,s.jsxs)(i,{isOpen:e,onClose:t,title:a,children:[(0,s.jsx)(c,{id:`username-select`,label:l,value:m,onChange:e=>h(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)(d,{id:`permission-level`,label:`Permissions`,value:g,onChange:e=>_(e),type:f,required:!0,containerClassName:`mb-4`}),(0,s.jsxs)(`div`,{className:`flex justify-end space-x-3`,children:[(0,s.jsx)(r,{onClick:t,variant:`ghost`,disabled:p,children:`Cancel`}),(0,s.jsx)(r,{onClick:()=>{v()},variant:`primary`,disabled:p||!m,children:p?`Saving...`:`Save`})]})]})};export{f as n,d as r,p as t};