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