"use strict";var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/slicedToArray"),i=require("react/jsx-runtime"),n=require("react"),l=require("prop-types"),a=require("classnames"),o=require("@material-ui/core"),r=require("@material-ui/icons/Edit"),s=require("@material-ui/icons/Close"),c=require("@material-ui/icons/Done"),u=require("../../IconButton/index.js");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=d(e),f=d(t),m=d(l),v=d(a),g=d(r),h=d(s),b=d(c),x=o.makeStyles((function(e){return{editableItem:{width:"100%",height:36,position:"relative",backgroundColor:e.palette.background.b8,"&:hover":{backgroundColor:"rgba(3, 188, 212, 0.07)"},"&:hover svg":{visibility:"visible"}},editableItemActive:{backgroundColor:"rgba(3, 188, 212, 0.15)  !important"},container:{display:"flex",alignItems:"center",justifyContent:"space-between","&:hover $editIcon":{visibility:"visible"}},value:{color:e.palette.primary.text6,fontSize:"0.875rem",height:"100%",letterSpacing:".13132px",lineHeight:"36px",overflow:"hidden",paddingLeft:48,textOverflow:"ellipsis",whiteSpace:"nowrap",width:"calc(100% - 32px)",userSelect:"none"},textField:{width:"100%"},inputRoot:{height:36,paddingLeft:48,fontSize:"0.875rem"},inputDisabled:{backgroundColor:"unset",paddingRight:16,"&::before":{display:"none"},pointerEvents:"none"},editIcon:{visibility:"hidden",marginRight:4},closeIcon:{color:e.palette.primary.text6,"&:hover svg":{fill:"".concat(e.palette.primary.contrastText," !important")},"& svg":{fill:"".concat(e.palette.primary.text6," !important"),"&:hover":{fill:"#FFFFFF !important"}}},inputAdornment:{marginTop:1,marginRight:4}}})),y=function(e){var t=e.className,l=e.isEditable,a=e.isEditing,r=e.onClick,s=e.onClickAway,c=e.onCancel,d=e.onSave,m=e.value,y=n.useState(m),k=f.default(y,2),C=k[0],j=k[1],w=n.useState(a),E=f.default(w,2),S=E[0],q=E[1],I=x(),A=function(e){var t;e.stopPropagation(),C.length&&C!==m&&(null==d||null===(t=d(C))||void 0===t||t.then((function(){return q(!1)})))};n.useEffect((function(){var e=function(e){"Escape"===e.key||"Esc"===e.key?(j(m),q(!1),null==s||s()):"Enter"===e.key&&A(e)};return S&&document.addEventListener("keydown",e),function(){return document.removeEventListener("keydown",e)}}),[S,m,C]);var F=function(e){e.stopPropagation(),j(m),q(!1),null==c||c()};n.useEffect((function(){j(m)}),[m]);var N=v.default(I.editableItem,p.default({},I.editableItemActive,S),t);return i.jsxs("div",{className:v.default(N,I.container),onClick:null!=r?r:void 0,children:[!S&&i.jsx("div",{className:I.value,children:C}),S&&i.jsx(o.ClickAwayListener,{onClickAway:function(){j(m),q(!1),null==s||s()},children:i.jsx(o.TextField,{autoFocus:!0,type:"text",value:C,onChange:function(e){e.stopPropagation(),j(e.target.value)},placeholder:"Page Name...",className:I.textField,InputProps:{classes:{root:I.inputRoot},endAdornment:S?i.jsx(o.InputAdornment,{position:"end",children:i.jsxs("span",{className:I.inputAdornment,children:[i.jsx(o.Tooltip,{title:"Cancel",placement:"bottom-end",children:i.jsx(u,{onClick:F,size:"small",className:I.closeIcon,children:i.jsx(h.default,{fontSize:"small"})})}),i.jsx(o.Tooltip,{title:"Save",placement:"bottom-end",children:i.jsx(u,{onClick:A,size:"small",disabled:C===m,children:i.jsx(b.default,{color:C===m?"disabled":"primary",fontSize:"small"})})})]})}):null}})}),l&&!S&&i.jsx(o.Tooltip,{title:"Rename Page",placement:"bottom-end",children:i.jsx(u,{className:I.editIcon,size:"small",onClick:function(e){e.stopPropagation(),q(!0)},children:i.jsx(g.default,{fontSize:"small"})})})]})},k={className:m.default.string,isEditable:m.default.bool,isEditing:m.default.bool,onClick:m.default.func,onSave:m.default.func.isRequired,onClickAway:m.default.func,onCancel:m.default.func,value:m.default.string.isRequired};y.propTypes=k,y.defaultProps={className:"",isEditable:!0,isEditing:!1,onClick:function(){},onClickAway:function(){},onCancel:function(){}},module.exports=y;
//# sourceMappingURL=index.js.map
