"use strict";var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/asyncToGenerator"),r=require("@babel/runtime/helpers/slicedToArray"),n=require("@babel/runtime/regenerator"),a=require("react"),i=require("prop-types"),s=require("classnames"),o=require("lodash"),u=require("moment"),d=require("@material-ui/core/styles"),c=require("@material-ui/core"),l=require("../../../../AnnotationsContext.js"),p=require("../../../../constants.js"),m=require("../AnnotationInput/index.js"),h=require("./style.css.js"),f=require("../../../../../Avatar/index.js"),q=require("../../../../../../effects/useOutsideClick.js");require("../../../../../../utils/index.js");var v=require("../../../../../../clients/jsonApi/index.js");require("../../../../../DevCenter/DevCenterRouterContext/DevCenterRouterContext.js"),require("../../../../../DevCenter/DevCenterRouterContext/UniversalLink/UniversalLink.js");var A=require("../../../../../DevCenter/DevCenterRouterContext/hocs/withUniversalLocationHOC.js"),y=require("react/jsx-runtime"),b=require("../../../../../../utils/notificationToasts.js");function j(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var x=j(e),C=j(t),I=j(r),g=j(n),N=j(s),R=j(u),_=function(e){var t,r=e.appId,n=e.assetId,i=e.assetCompanyId,s=e.appSettings,u=e.currentUser,d=e.classes,A=e.location,j=e.dashboardType,_=l.useAnnotationsDispatch(),T=a.useState(!1),D=I.default(T,2),w=D[0],P=D[1],U=a.useRef(null);q(U,(function(){P(!1)}));var F,k=(F=C.default(g.default.mark((function e(t,a,i){var u,d,c,l;return g.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,u={app_id:r,asset_id:n,body:t,active_until:a,attachment:{file_name:i&&i.attachmentName,s3_link:i&&i.attachmentUrl},settings:s},d={},j&&(d.dashboard_type=j),(c=o.get(A,"query.time"))&&(u.data_timestamp=R.default(c).format()),e.next=8,v.postAnnotation(u,d);case 8:l=e.sent,_({type:p.ADD_ANNOTATION,annotation:l}),e.next=17;break;case 12:return e.prev=12,e.t0=e.catch(0),b.showErrorNotification("Error during annotation creation"),console.error(e.t0),e.abrupt("return");case 17:b.showSuccessNotification("Annotation has been added"),P(!1);case 19:case"end":return e.stop()}}),e,null,[[0,12]])}))),function(e,t,r){return F.apply(this,arguments)});return y.jsxs("div",{className:h.cAddAnnotationFormInput,children:[y.jsx(f.AvatarComponent,{displayName:"".concat(u.first_name," ").concat(u.last_name),imgSrc:u.profile_photo,size:36}),y.jsxs("div",{className:N.default(h.cAddAnnotationFormInputPaper,(t={},x.default(t,h.cAddAnnotationFormInputPaperOpened,w),x.default(t,h.cAddAnnotationFormInputPaperClosed,!w),t)),children:[y.jsx(c.Fade,{in:!w,timeout:500,children:y.jsx(c.Paper,{className:h.cAddAnnotationFormInputPaperLabel,children:y.jsx(c.Typography,{variant:"body2","data-testid":"".concat("AppAnnotationsPo","_collapsedInput"),className:d.inputLabel,onClick:function(){return P(!0)},children:"Type annotation here"})})}),y.jsx(c.Fade,{in:w,timeout:100,children:y.jsx("div",{className:h.cAddAnnotationFormInputPaperAddAnnotation,children:w&&y.jsx(m,{onSend:k,assetCompanyId:i,currentUser:u})})})]})]})};_.propTypes={appId:i.number.isRequired,assetId:i.number.isRequired,assetCompanyId:i.number.isRequired,appSettings:i.shape().isRequired,currentUser:i.shape({}),classes:i.shape().isRequired,location:i.shape().isRequired,dashboardType:i.string},_.defaultProps={currentUser:{},dashboardType:null};var T=o.flowRight([d.withStyles((function(e){return{inputLabel:{color:e.palette.grey[700],fontWeight:200,width:"100%"}}})),A.withUniversalLocationHOC])(a.memo(_));module.exports=T;
