import e from"@babel/runtime/helpers/slicedToArray";import{jsx as r}from"react/jsx-runtime";import{useState as o,useCallback as t,useEffect as n,useMemo as i}from"react";import{TextInput as a}from"../../TextInput/TextInput.js";import{Modal as l}from"../../Modal/Modal.js";import{storeApi as m}from"../Store/Store.js";import"../Store/utils.js";import{suggestName as s}from"../utils.js";var u=function(u){var p=u.onCreate,c=u.open,d=u.onClose,f=u.title,y=u.initialName,T=void 0===y?"":y,b=m.useAllTemplates,v=o(T),A=e(v,2),j=A[0],x=A[1],C=b(),h=s(j,C),g=t((function(){p(j),d()}),[p,j,d]);n((function(){c&&x(T)}),[T,c]);var S=i((function(){var e;return{disabled:!(null!=j&&null!==(e=j.trim())&&void 0!==e&&e.length&&!h)}}),[j,h]),H=t((function(e){"Enter"!==e.key||S.disabled||g()}),[g,S.disabled]);return r(l,{open:c,size:"small",title:f,onClose:d,primaryActionText:"Create",primaryActionHandler:g,primaryActionProps:S,secondaryActionText:"Cancel",secondaryActionHandler:d,children:r(a,{label:"Template name",value:j,onChange:x,onKeyUp:H,autoFocus:!0,message:h&&'Name should be unique. Try "'.concat(h,'"')})})};export{u as AddModal};
//# sourceMappingURL=AddModal.js.map
