"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react/jsx-runtime"),n=require("react"),r=require("moment"),a=require("../../Store/Store.js");require("../../Store/utils.js");var i=require("../../../Tooltip/Tooltip.js"),u=require("../../utils.js"),o=require("../../../ButtonIcon/ButtonIcon.js"),l=require("../../UnsavedChangesBadge/UnsavedChangesBadge.js"),s=require("../IconMenu/IconMenu.js"),d=require("../../TemplatesTreeMenuHeader/TemplatesTreeMenuHeader.js"),c=require("../../types.js"),p=require("./MenuHeader.scss.js");function m(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var v=m(e),f=m(r);exports.MenuHeader=function(){var e,r=a.storeApi.useTemplateMenuData,m=a.storeApi.useTemplateById,T=a.storeApi.useSelectedTemplate,j=a.storeApi.useHasUnsavedChanges,g=a.storeApi.useAllTemplates,b=a.storeApi.useTemplateIcon,h=a.storeApi.useTemplateIconColor,q=a.storeApi.useUpdateTemplateIcon,A=a.storeApi.useHasCurrentAction,C=a.storeApi.useUpdateTemplateName,I=r(),M=T(),x=j(null==I?void 0:I.templateId),y=g(),U=m(null==I?void 0:I.templateId),B=h(U),H=q(),N=b(U),S=A(null==U?void 0:U.id,c.Action.UpdateMetadata),k=A(null==U?void 0:U.id,c.Action.UpdateName),E=C(),_=n.useRef(null),w=n.useState(!1),O=v.default(w,2),P=O[0],z=O[1],D=n.useMemo((function(){return y.filter((function(e){return e.id!==(null==U?void 0:U.id)}))}),[y,null==U?void 0:U.id]),F=n.useCallback((function(e){var t=0===e.trim().length?"Template must have a name":"",n=t?"":u.suggestName(e,D),r=n?'Name should be unique. Try "'.concat(n,'"'):t,a=r||function(e){if(null!=e&&e.updated_at){var t=f.default(e.updated_at).fromNow();return"".concat(e.published?"Published":"Edited"," ").concat(t)}return""}(U);return{message:a,hasError:!!r}}),[D,U]),R=n.useCallback((function(e){E(null==U?void 0:U.id,e)}),[null==U?void 0:U.id,E]),V=n.useCallback((function(){return z((function(e){return!e}))}),[]),G=n.useCallback((function(e){var t=e.icon,n=e.iconColor;V(),H(null==U?void 0:U.id,{icon:t,iconColor:n})}),[null==U?void 0:U.id,V,H]);if(!U)return null;var J=u.isOwnTemplate(U);return t.jsxs(t.Fragment,{children:[t.jsx(d.TemplatesTreeMenuHeader,{entityName:null==U?void 0:U.name,onSave:R,badge:U.id===(null==M?void 0:M.id)&&x&&t.jsx(l.UnsavedChangesBadge,{className:p.unsavedChanges}),button:t.jsx(i.Tooltip,{title:"Edit Icon",disabled:!J,children:t.jsx(o.ButtonIcon,{size:"small",disabled:!J||S,type:"tertiaryBg",ref:_,onClick:V,children:t.jsx(N,{color:B})})}),isEditable:J,isUpdating:k,getValidation:F}),t.jsx(s.IconMenu,{open:P,onSave:G,anchorEl:_.current,icon:null===(e=U.metadata)||void 0===e?void 0:e.icon,iconColor:B})]})};
//# sourceMappingURL=MenuHeader.js.map
