import t from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/asyncToGenerator";import n from"@babel/runtime/helpers/slicedToArray";import o from"@babel/runtime/regenerator";import{memo as r,useRef as a,useState as i,useEffect as s}from"react";import{number as c,string as p,shape as d,func as m,bool as l}from"prop-types";import u from"classnames";import{withStyles as f}from"@material-ui/core/styles";import{RootRef as h,Paper as y,Typography as b,Tooltip as g,IconButton as A}from"@material-ui/core";import v from"@material-ui/icons/ChevronLeft";import{getAnnotations as I}from"../../../../clients/jsonApi/index.js";import{useAnnotationsState as C,useAnnotationsDispatch as T}from"../../AnnotationsContext.js";import{SET_ANNOTATIONS as N,APPEND_ANNOTATIONS as x}from"../../constants.js";import j from"./components/AddAnnotationForm/index.js";import L from"./components/Annotation/index.js";import k from"./style.css.js";import"../../../../utils/index.js";import{isNativeDetected as R}from"../../../../utils/mobileDetect.js";import _ from"../../../InfiniteList/index.js";import q from"../../../../effects/useOutsideClick.js";import{jsx as w,jsxs as S,Fragment as H}from"react/jsx-runtime";import{showSuccessNotification as U}from"../../../../utils/notificationToasts.js";var F="AppAnnotationsPo",O=function(r){var c,p=r.appId,d=r.appTitle,m=r.assetId,l=r.assetCompanyId,f=r.appSettings,R=r.currentUser,O=r.onClose,P=r.isNative,W=r.classes,B=r.dashboardType,D=C().annotations,E=T(),G=a(),M=a();q(G,O);var z=i(!1),J=n(z,2),K=J[0],Q=J[1],V=i(!0),X=n(V,2),Y=X[0],Z=X[1],$=i(!0),tt=n($,2),et=tt[0],nt=tt[1],ot=i(1),rt=n(ot,2),at=rt[0],it=rt[1];function st(){return(st=e(o.mark((function t(){var e,n,r;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p&&m){t.next=2;break}return t.abrupt("return");case 2:return Z(!0),t.prev=3,n={page:at,per_page:4,sort:"created_at",order:"desc"},B&&(n.dashboard_type=B),t.next=8,I(p,m,n);case 8:e=t.sent,E({type:1===at?N:x,annotations:e}),t.next=15;break;case 12:t.prev=12,t.t0=t.catch(3),console.error(t.t0);case 15:r=e&&e.data.length<4,it(at+1),nt(!r),Z(!1);case 19:case"end":return t.stop()}}),t,null,[[3,12]])})))).apply(this,arguments)}return s((function(){Q(!0)}),[]),w(h,{rootRef:G,children:S(y,{className:u(k.cAnnotationsList,(c={},t(c,k.cAnnotationsListOpen,K),t(c,k.cAnnotationsListOpenNative,P),c)),children:[w(_,{infiniteClassName:k.cAnnotationsListContentContainer,headerComponent:S(H,{children:[w(b,{"data-testid":"".concat(F,"_appTitle"),variant:"body1",className:W.title,children:d}),w("div",{className:k.cAnnotationsListContentTop,children:S(b,{"data-testid":"".concat(F,"_annotationsTitle"),variant:"caption",className:W.secondaryTitle,children:["Annotations (",D.data?D.data.length:0,")"]})}),w(j,{appId:p,assetId:m,assetCompanyId:l,appSettings:f,currentUser:R,dashboardType:B})]}),useWindow:P,items:D.data||[],showNoItemsFound:!(D.data&&0!==D.data.length||Y),noItemsFoundLabel:w(b,{variant:"body2","data-testid":"".concat(F,"_noAnnotations"),className:W.noAnnotations,children:"No Annotations yet"}),threshold:50,infiniteContainerHeight:G.current&&M.current?G.current.clientHeight-M.current.clientHeight:null,moreItemsMayExist:et,pathToCreatedAt:["attributes","created_at"],renderItem:function(t){return w(L,{isNative:P,annotation:t,assetCompanyId:l,included:D.included,currentUser:R,showSuccessNotification:U},t.id)},loadItems:function(){return st.apply(this,arguments)}}),w("div",{className:k.cAnnotationsListActions,ref:M,children:w(g,{title:"Hide",placement:"bottom",children:w(A,{"data-testid":"".concat(F,"_hideButton"),onClick:O,className:W.backIcon,children:w(v,{})})})})]})})};O.propTypes={appId:c.isRequired,appTitle:p.isRequired,assetId:c.isRequired,assetCompanyId:c.isRequired,appSettings:d(),classes:d().isRequired,onClose:m.isRequired,currentUser:d({}).isRequired,isNative:l,dashboardType:p},O.defaultProps={appSettings:{},isNative:R,dashboardType:null};var P=f((function(t){return{title:{fontWeight:200,marginBottom:20},secondaryTitle:{fontWeight:200,textTransform:"uppercase",color:t.palette.grey[600]},annotateIcon:{padding:0,"&:hover":{backgroundColor:"transparent",boxShadow:"none"}},noAnnotations:{marginTop:16},backIcon:{cursor:"pointer",color:t.palette.grey[600],padding:5}}}))(r(O));export{P as default};
//# sourceMappingURL=index.js.map
