"use strict";(globalThis.webpackChunk_openmrs_esm_bed_management_app=globalThis.webpackChunk_openmrs_esm_bed_management_app||[]).push([["52"],{60862:function(e,t,n){n.d(t,{Z:()=>b});var a=n(27350),r=n.n(a),l=n(98900),o=n(20366),i=n(54675),c=n(94180),u=n(68892),d=n(93798);function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=Array(t);n<t;n++)a[n]=e[n];return a}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,a,r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var l=[],o=!0,i=!1;try{for(r=r.call(e);!(o=(n=r.next()).done)&&(l.push(n.value),!t||l.length!==t);o=!0);}catch(e){i=!0,a=e}finally{try{o||null==r.return||r.return()}finally{if(i)throw a}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(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 s(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,s=e.closeModal,b=(0,u.useTranslation)().t,g=m((0,a.useState)(!1),2),y=g[0],p=g[1],h=m((0,a.useState)(""),2),T=h[0],v=h[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 r().createElement(r().Fragment,null,r().createElement(c.xBx,{title:n,closeModal:s}),r().createElement(c.fef,{hasScrollingContent:!0},r().createElement(c.l09,null,r().createElement(c.Kqy,{gap:3},r().createElement(c.cwH,{legendText:""},r().createElement(o.Qr,{name:"name",control:k,render:function(e){var t,n=e.field,a=e.fieldState;return r().createElement(r().Fragment,null,r().createElement(c.oil,function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},a=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(a=a.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),a.forEach(function(t){var a;a=n[t],t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a})}return e}({id:"bedTag",labelText:b("bedTagName","Name of the bed tag"),placeholder:b("bedTagPlaceholder",""),invalidText:null==(t=a.error)?void 0:t.message},n)))}})),y&&r().createElement(c.K0D,{lowContrast:!0,title:b("error","Error"),style:{minWidth:"100%",margin:"0",padding:"0"},role:"alert",kind:"error",subtitle:b("pleaseFillField",T)+".",onClose:function(){return p(!1)}})))),r().createElement(c.mzw,null,r().createElement(c.zxk,{onClick:s,kind:"secondary"},(0,d.getCoreTranslation)("cancel","Cancel")),r().createElement(c.zxk,{disabled:!C,onClick:S(function(e){f.safeParse(e).success&&(p(!1),t(e))},function(e){v(Object.entries(e)[0][1].message),p(!0)})},r().createElement("span",null,b("save","Save")))))}},23829:function(e,t,n){n.r(t),n.d(t,{default:()=>u});var a=n(27350),r=n.n(a),l=n(68892),o=n(93798),i=n(66210),c=n(60862);let u=function(e){var t=e.editData,n=e.mutate,u=e.closeModal,d=(0,l.useTranslation)().t,s=(0,i.ly)().bedTags,m=d("editTag","Edit Tag"),f=(0,a.useCallback)(function(e){var a=t.uuid,r={name:e.name};(0,i.Ep)({bedTagPayload:r,bedTagId:a}).then(function(){(0,o.showSnackbar)({kind:"success",title:d("bedTagUpdated","Bed tag updated"),subtitle:d("bedTagUpdatedSuccessfully","{{bedTag}} updated successfully",{bedTag:r.name})}),n()}).catch(function(e){(0,o.showSnackbar)({kind:"error",title:d("errorCreatingBedTag","Error creating bed tag"),subtitle:null==e?void 0:e.message})}).finally(u)},[t.uuid,u,d,n]);return r().createElement(r().Fragment,null,r().createElement(c.Z,{allLocations:[],availableBedTags:s,handleCreateBedTag:f,headerTitle:m,initialData:t,closeModal:u}))}}}]);