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