"use strict";(globalThis.webpackChunk_openmrs_esm_bed_management_app=globalThis.webpackChunk_openmrs_esm_bed_management_app||[]).push([["4166"],{60862:function(e,t,n){n.d(t,{Z:()=>b});var r=n(27350),a=n.n(r),l=n(98900),o=n(20366),i=n(54675),c=n(94180),u=n(68892),s=n(93798);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,i=!1;try{for(a=a.call(e);!(o=(n=a.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==a.return||a.return()}finally{if(i)throw r}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return d(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var f=l.Ry({name:l.Z_().max(255)});let b=function(e){var t=e.handleCreateBedTag,n=e.headerTitle,l=e.initialData,d=e.closeModal,b=(0,u.useTranslation)().t,g=m((0,r.useState)(!1),2),y=g[0],h=g[1],p=m((0,r.useState)(""),2),v=p[0],T=p[1],E=(0,o.cI)({mode:"all",resolver:(0,i.F)(f),defaultValues:{name:l.name||""}}),S=E.handleSubmit,k=E.control,C=E.formState.isDirty;return a().createElement(a().Fragment,null,a().createElement(c.xBx,{title:n,closeModal:d}),a().createElement(c.fef,{hasScrollingContent:!0},a().createElement(c.l09,null,a().createElement(c.Kqy,{gap:3},a().createElement(c.cwH,{legendText:""},a().createElement(o.Qr,{name:"name",control:k,render:function(e){var t,n=e.field,r=e.fieldState;return a().createElement(a().Fragment,null,a().createElement(c.oil,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({id:"bedTag",labelText:b("bedTagName","Name of the bed tag"),placeholder:b("bedTagPlaceholder",""),invalidText:null==(t=r.error)?void 0:t.message},n)))}})),y&&a().createElement(c.K0D,{lowContrast:!0,title:b("error","Error"),style:{minWidth:"100%",margin:"0",padding:"0"},role:"alert",kind:"error",subtitle:b("pleaseFillField",v)+".",onClose:function(){return h(!1)}})))),a().createElement(c.mzw,null,a().createElement(c.zxk,{onClick:d,kind:"secondary"},(0,s.getCoreTranslation)("cancel","Cancel")),a().createElement(c.zxk,{disabled:!C,onClick:S(function(e){f.safeParse(e).success&&(h(!1),t(e))},function(e){T(Object.entries(e)[0][1].message),h(!0)})},a().createElement("span",null,b("save","Save")))))}},29813:function(e,t,n){n.r(t),n.d(t,{default:()=>u});var r=n(27350),a=n.n(r),l=n(68892),o=n(93798),i=n(66210),c=n(60862);let u=function(e){var t=e.closeModal,n=e.mutate,u=(0,l.useTranslation)().t,s=(0,i.Si)().admissionLocations,d=(0,i.ly)().bedTags,m=u("createBedTag","Create bed tag"),f=(0,r.useCallback)(function(e){var r=e.name;(0,i.dk)({bedTagPayload:{name:r}}).then(function(){(0,o.showSnackbar)({kind:"success",title:u("bedTagCreated","Bed tag created"),subtitle:u("bedTagCreatedSuccessfully","".concat(r," created successfully"),{bedTag:r})}),n()}).catch(function(e){(0,o.showSnackbar)({kind:"error",title:u("errorCreatingForm","Error creating bed"),subtitle:null==e?void 0:e.message})}).finally(t)},[t,u,n]);return a().createElement(c.Z,{allLocations:s,availableBedTags:d,handleCreateBedTag:f,headerTitle:m,initialData:{name:"",uuid:""},closeModal:t})}}}]);