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