import{j as e}from"./vendor-mui-69397583.js";import{r as y}from"./vendor-react-ece1c85f.js";import{a as p,F as b}from"./FormContainer-91c2b0e4.js";import{I as u,B as d,al as w}from"./index-c62ac197.js";import{h as S}from"./index-36ba4ea7.js";import{S as A}from"./StickyFooter-5b934274.js";import{C as T}from"./ConfirmDialog-3202eb3d.js";import{d as x,a as I,c as k,F as v,b as D}from"./index.esm-70ab539c.js";import{A as E}from"./AdaptableCard-df7695d6.js";import{a as F}from"./index-e4c6057f.js";import{V as f,i as N}from"./validationPatterns-77446c46.js";const q=t=>{const{touched:r,errors:s,type:i}=t;return e.jsxs(E,{className:"mb-4",children:[e.jsx(p,{asterisk:!0,label:"Role",invalid:s.name&&r.name,errorMessage:s.name,children:e.jsx(x,{type:"text",autoComplete:"off",name:"name",placeholder:"Role",component:u})}),e.jsx(p,{asterisk:!0,label:"Description",invalid:s.description&&r.description,errorMessage:s.description,children:e.jsx(x,{textArea:!0,type:"text",autoComplete:"off",name:"description",placeholder:"Description",component:u})})]})},B={TEXT_INPUT:100,TEXT_AREA:255,PASSWORD:50,USERNAME:30},{TEXT_INPUT:h,TEXT_AREA:j}=B,{useUniqueId:O}=S,g=I().matches(f.sqlInjectionSafe,"Invalid input: SQL keywords not allowed").matches(f.noSpecialChars,"Special characters like < > = { } are not allowed").test("no-base64","Base64 encoded content is not allowed",t=>t?!N(t.trim()):!0),M=k().shape({name:g.required("Role Required").max(h,`Maximum ${h} characters allowed`),description:g.required("Description Required").max(j,`Maximum ${j} characters allowed`)}),_=({onDelete:t})=>{const[r,s]=y.useState(!1),i=()=>{s(!0)},o=()=>{s(!1)},a=()=>{t==null||t(s)};return e.jsxs(e.Fragment,{children:[e.jsx(d,{className:"text-red-600",variant:"plain",size:"sm",icon:e.jsx(w,{}),type:"button",onClick:i,children:"Delete"}),e.jsx(T,{isOpen:r,type:"danger",title:"Delete product",confirmButtonColor:"red-600",onClose:o,onRequestClose:o,onCancel:o,onConfirm:a,children:e.jsx("p",{children:"Are you sure you want to delete this role? All record related to this role will be deleted as well. This action cannot be undone."})})]})},X=y.forwardRef((t,r)=>{const{type:s,footerWidth:i,initialData:o={id:"",name:"",description:""},onFormSubmit:a,onDiscard:l,onDelete:C}=t,R=O("Role-");return e.jsx(e.Fragment,{children:e.jsx(v,{innerRef:r,initialValues:{...o},validationSchema:M,onSubmit:(m,{setSubmitting:c})=>{const n=m;s==="new"&&(n.id=R),a==null||a(n,c)},children:({values:m,touched:c,errors:n,isSubmitting:$})=>e.jsx(D,{children:e.jsxs(b,{children:[e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-1 gap-4",children:e.jsx("div",{className:"lg:col-span-2",children:e.jsx(q,{type:s,touched:c,errors:n})})}),e.jsxs(A,{className:`px-8 flex items-center justify-between py-4 ${i}`,stickyClass:"bg-white dark:bg-gray-800 border-gray-200 dark:border-gray-700",children:[e.jsx("div",{children:s==="edit"&&e.jsx(_,{onDelete:C})}),e.jsxs("div",{className:"md:flex items-center justify-between w-full",children:[e.jsx(d,{size:"sm",className:"ltr:mr-3 rtl:ml-3",type:"button",onClick:()=>l==null?void 0:l(),children:"Discard"}),e.jsx(d,{size:"sm",variant:"solid",icon:e.jsx(F,{}),type:"submit",children:"Save"})]})]})]})})})})});X.displayName="RoleForm";export{X as R};
