"use strict";var e=require("react/jsx-runtime"),t=require("react"),i=require("prop-types"),n=require("classnames"),o=require("@material-ui/core"),a=require("@material-ui/icons/Edit"),l=require("@material-ui/icons/Close"),r=require("@material-ui/icons/Done"),s=require("../../IconButton/index.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=c(i),u=c(n),p=c(a),m=c(l),f=c(r),g=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}}})),v=function(i){var n,a=i.className,l=i.isEditable,r=i.isEditing,c=i.onClick,d=i.onClickAway,v=i.onCancel,h=i.onSave,b=i.value,x=t.useState(b),y=x[0],k=x[1],C=t.useState(r),j=C[0],w=C[1],E=g(),S=function(e){e.stopPropagation(),y.length&&y!==b&&h(y).then((function(){return w(!1)}))};t.useEffect((function(){var e=function(e){"Escape"===e.key||"Esc"===e.key?(k(b),w(!1),d()):"Enter"===e.key&&S(e)};return j&&document.addEventListener("keydown",e),function(){return document.removeEventListener("keydown",e)}}),[j,b,y]);var I=function(e){e.stopPropagation(),k(b),w(!1),v()};t.useEffect((function(){k(b)}),[b]);var q=u.default(E.editableItem,((n={})[E.editableItemActive]=j,n),a);return e.jsxs("div",{className:u.default(q,E.container),onClick:c,children:[!j&&e.jsx("div",{className:E.value,children:y}),j&&e.jsx(o.ClickAwayListener,{onClickAway:function(){k(b),w(!1),d()},children:e.jsx(o.TextField,{autoFocus:!0,type:"text",value:y,onChange:function(e){e.stopPropagation(),k(e.target.value)},placeholder:"Page Name...",className:E.textField,InputProps:{classes:{root:E.inputRoot},endAdornment:j?e.jsx(o.InputAdornment,{position:"end",children:e.jsxs("span",{className:E.inputAdornment,children:[e.jsx(o.Tooltip,{title:"Cancel",placement:"bottom-end",children:e.jsx(s,{onClick:I,size:"small",className:E.closeIcon,children:e.jsx(m.default,{fontSize:"small"})})}),e.jsx(o.Tooltip,{title:"Save",placement:"bottom-end",children:e.jsx(s,{onClick:S,size:"small",disabled:y===b,children:e.jsx(f.default,{color:y===b?"disabled":"primary",fontSize:"small"})})})]})}):null}})}),l&&!j&&e.jsx(o.Tooltip,{title:"Rename Page",placement:"bottom-end",children:e.jsx(s,{className:E.editIcon,size:"small",onClick:function(e){e.stopPropagation(),w(!0)},children:e.jsx(p.default,{fontSize:"small"})})})]})},h={className:d.default.string,isEditable:d.default.bool,isEditing:d.default.bool,onClick:d.default.func,onSave:d.default.func.isRequired,onClickAway:d.default.func,onCancel:d.default.func,value:d.default.string.isRequired};v.propTypes=h,v.defaultProps={className:"",isEditable:!0,isEditing:!1,onClick:function(){},onClickAway:function(){},onCancel:function(){}},module.exports=v;
