"use strict";(self.webpackChunkhws_plugin_authorization_access_manager=self.webpackChunkhws_plugin_authorization_access_manager||[]).push([[4762],{44762:function(e,i,n){n.r(i),n.d(i,{default:function(){return w}});var l=n(77528),t=n(55456),a=n(1995),s=n(25793),r=n(20068),o=n(7027),c=n(28792),d=n(12473),m=n(18160),u=n(3665),x=n(26385),_=n(44056),A=n(29434),v=n(46141),N=n(3718),p=n(85052),h=n(6701);let f=e=>{var i,n,l,t;return null!==(t=null===(l=window)||void 0===l?void 0:null===(n=l.HWS)||void 0===n?void 0:null===(i=n.I18n)||void 0===i?void 0:i.t(e))&&void 0!==t?t:e};var T=function(){var e,i;let{saveData:n}=(0,N.A)(),l=new URLSearchParams(location.search),t=null!==(e=l.get("action"))&&void 0!==e?e:"",o=null!==(i=l.get("id"))&&void 0!==i?i:null,{formState:c,handleSubmit:d,trigger:T,setValue:E}=(0,r.useFormContext)(),{isValid:I}=c,[S,w]=(0,A.useState)(!1),j=(0,u.A)(),C=(0,s.useNavigate)(),y=()=>{w(!0),d(async e=>{var i,l;let t={Name:null===(i=e.name)||void 0===i?void 0:i.trim(),Description:null===(l=e.description)||void 0===l?void 0:l.trim()};Object.entries(t).forEach(e=>{let[i,n]=e;E(i.toLowerCase(),n)}),await T()&&(await n(p.H.PolicyAttributeTypes,t,null!=o?o:void 0),C("/plugin/access-manager/attribute-types")),w(!1)})()};return(0,a.jsxs)("div",{className:"flex flex-col sm:flex-row flex-1 w-full items-center justify-between space-y-8 sm:space-y-0 py-24 sm:py-32 px-24 md:px-32",children:[(0,a.jsxs)("div",{className:"flex flex-col items-start space-y-8 sm:space-y-0 w-full sm:max-w-full min-w-0",children:[(0,a.jsxs)(_.motion.div,{initial:{x:20,opacity:0},animate:{x:0,opacity:1,transition:{delay:.3}},children:[(0,a.jsx)(h.Gy,{}),(0,a.jsxs)(x.A,{className:"flex items-center sm:mb-12",component:s.Link,role:"button",to:"/plugin/access-manager/attribute-types",color:"inherit",children:[(0,a.jsx)(h.ri,{size:20,children:"ltr"===j.direction?"heroicons-outline:arrow-sm-left":"heroicons-outline:arrow-sm-right"}),(0,a.jsx)("span",{className:"flex mx-4 font-medium",children:f("HWS_PLUGIN_AUTHORIZATION_ACCESS_MANAGER_ATTRIBUTE_TYPES")})]})]}),(0,a.jsx)("div",{className:"flex items-center max-w-full",children:(0,a.jsx)(_.motion.div,{className:"flex flex-col min-w-0 mx-8 sm:mx-16",initial:{x:-20},animate:{x:0,transition:{delay:.3}},children:(0,a.jsx)(x.A,{className:"text-16 sm:text-20 truncate font-semibold",children:"create"===t?f("HWS_PLUGIN_AUTHORIZATION_ACCESS_MANAGER_NEW_ATTRIBUTE_TYPE"):f("HWS_PLUGIN_AUTHORIZATION_ACCESS_MANAGER_EDIT_ATTRIBUTE_TYPE")})})})]}),(0,a.jsx)(_.motion.div,{className:"flex flex-1 w-full",initial:{opacity:0,x:20},animate:{opacity:1,x:0,transition:{delay:.3}},children:"create"!==t?(0,a.jsx)(a.Fragment,{children:(0,a.jsxs)(m.A,{className:"whitespace-nowrap mx-4",variant:"contained",color:"secondary",disabled:!I||S,onClick:y,children:[f("HWS_PLUGIN_AUTHORIZATION_ACCESS_MANAGER_SAVE"),S&&(0,a.jsx)(v.A,{style:{marginLeft:"3px"},size:"2rem"})]})}):(0,a.jsxs)(m.A,{className:"whitespace-nowrap mx-4",variant:"contained",color:"secondary",disabled:!I||S,onClick:y,children:[f("HWS_PLUGIN_AUTHORIZATION_ACCESS_MANAGER_CREATE"),S&&(0,a.jsx)(v.A,{style:{marginLeft:"3px"},size:"2rem"})]})})]})};let E=e=>{var i,n,l,t;return null!==(t=null===(l=window)||void 0===l?void 0:null===(n=l.HWS)||void 0===n?void 0:null===(i=n.I18n)||void 0===i?void 0:i.t(e))&&void 0!==t?t:e},I=d.z.object({name:d.z.string().min(1,"HWS_PLUGIN_AUTHORIZATION_ACCESS_MANAGER_NAME_CANNOT_BE_EMPTY"),description:d.z.string().optional()}),S={name:"",description:""};var w=function(){var e;(0,s.useParams)().action;let i=new URLSearchParams(location.search),n=i.get("action"),d=i.get("id"),{policyAttributeTypes:m}=(0,N.A)(),u=(0,r.useForm)({mode:"onChange",defaultValues:S,resolver:(0,c.u)(I)}),{control:x,formState:_,reset:v}=u,{errors:p}=_;return((0,A.useEffect)(()=>{var e;if(n&&"edit"===n&&(null==m?void 0:null===(e=m.data)||void 0===e?void 0:e.length)>0){let e=m.data.find(e=>e.Id==d);e&&v({name:e.Name,description:e.Description})}},[n,d,v,m]),null==m?void 0:null===(e=m.permissions)||void 0===e?void 0:e.includes("Write"))?(0,a.jsx)(r.FormProvider,(0,t._)((0,l._)({},u),{children:(0,a.jsx)(h.Ow,{header:(0,a.jsx)(T,{}),content:(0,a.jsx)(a.Fragment,{children:(0,a.jsxs)("div",{className:"p-16 sm:p-24 max-w-3xl",children:[(0,a.jsx)(r.Controller,{name:"name",control:x,render:e=>{var i,n;let{field:s}=e;return(0,a.jsx)(o.A,(0,t._)((0,l._)({},s),{className:"mt-8 mb-16",required:!0,label:E("HWS_PLUGIN_AUTHORIZATION_ACCESS_MANAGER_NAME"),autoFocus:!0,id:"name",variant:"outlined",fullWidth:!0,error:!!p.name,helperText:E(null!==(n=null==p?void 0:null===(i=p.name)||void 0===i?void 0:i.message)&&void 0!==n?n:"")}))}}),(0,a.jsx)(r.Controller,{name:"description",control:x,render:e=>{let{field:i}=e;return(0,a.jsx)(o.A,(0,t._)((0,l._)({},i),{className:"mt-8 mb-16",id:"description",label:E("HWS_PLUGIN_AUTHORIZATION_ACCESS_MANAGER_DESCRIPTION"),type:"text",multiline:!0,rows:5,variant:"outlined",fullWidth:!0}))}})]})}),scroll:"content"})})):(0,a.jsx)(h.mg,{})}}}]);