"use strict";var e=require("@babel/runtime/helpers/asyncToGenerator"),t=require("@babel/runtime/helpers/toConsumableArray"),n=require("@babel/runtime/helpers/slicedToArray"),r=require("@babel/runtime/regenerator"),s=require("react"),a=require("prop-types"),o=require("@material-ui/core/styles"),i=require("@material-ui/core"),u=require("./style.css.js"),c=require("../../../../../../clients/jsonApi/index.js"),l=require("../../../../../LoadingIndicator/LoadingIndicator.js"),m=require("../../../../../CommentInput/index.js"),d=require("../../../../../CommentLoader.js"),p=require("../../../../../Comment/index.js"),f=require("react/jsx-runtime");function C(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=C(e),b=C(t),x=C(n),q=C(r),v=function(e){var t=e.annotationId,n=e.commentInputIsOpen,r=e.commentsCount,a=e.setCommentsCount,o=e.initialCommentsCount,C=e.classes,v=e.assetCompanyId,j=e.currentUser,y=s.useRef(),I=s.useState([]),g=x.default(I,2),k=g[0],w=g[1],A=s.useState(!1),R=x.default(A,2),L=R[0],S=R[1],T=s.useState(!1),M=x.default(T,2),N=M[0],U=M[1],_=s.useState(1),O=x.default(_,2),V=O[0],z=O[1],B=s.useState(3),D=x.default(B,2),E=D[0],G=D[1],P=function(e){var t=k.findIndex((function(t){return t.id===e.id})),n=b.default(k);n.splice(t,1,e),w(n)},F=function(e){w(k.filter((function(t){return t.id!==e}))),a(r-1)};s.useEffect((function(){function e(){return(e=h.default(q.default.mark((function e(){var n;return q.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return");case 2:return S(!0),e.prev=3,e.next=6,c.getAnnotationComments(t,{page:V,per_page:3,order:"desc"});case 6:n=e.sent,w(n),e.next=13;break;case 10:e.prev=10,e.t0=e.catch(3),console.error(e.t0);case 13:S(!1);case 14:case"end":return e.stop()}}),e,null,[[3,10]])})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[]);var H,J=(H=h.default(q.default.mark((function e(){var n,s,a;return q.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return S(!0),G((s=(n=3===E)?7:10)+E),e.prev=4,e.next=7,c.getAnnotationComments(t,{page:n?1:V,per_page:s,order:"desc",offset:1===V?k.length:r-o+10});case 7:a=e.sent,w([].concat(b.default(k),b.default(a))),n||z(V+1),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(4),console.error(e.t0);case 15:S(!1);case 16:case"end":return e.stop()}}),e,null,[[4,12]])}))),function(){return H.apply(this,arguments)}),K=k.slice(0,E).reverse(),Q=r>E;return L&&!k.length?f.jsx(l,{fullscreen:!1}):f.jsxs("div",{className:u.cAnnotationCommentsList,children:[Q&&f.jsx(i.Button,{"data-testid":"".concat("annotationComments","_viewMoreComments"),className:C.showMore,onClick:J,children:f.jsx(i.Typography,{variant:"caption",color:"primary",children:"View more comments"})}),f.jsxs("div",{className:u.cAnnotationCommentsListItems,children:[L&&k.length&&f.jsx(l,{fullscreen:!1,size:30}),K.map((function(e){return f.jsx(p,{comment:e,handleDeleteCallback:F,patchCommentCallback:P,companyId:v,currentUser:j},e.id)}))]}),N&&f.jsx(d,{spaceAround:!0}),n&&f.jsx("div",{className:u.cAnnotationCommentsListInput,children:f.jsx(m,{inputRef:y,postComment:function(e){return c.postAnnotationComment(t,e)},setIsPosting:U,postCommentCallback:function(e){w([e].concat(b.default(k))),a(r+1)},onMount:function(){var e=y.current;e&&(e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"start"}),e.focus())},companyId:v,currentUser:j})})]})};v.propTypes={annotationId:a.string.isRequired,commentInputIsOpen:a.bool.isRequired,commentsCount:a.number.isRequired,initialCommentsCount:a.number.isRequired,setCommentsCount:a.func.isRequired,classes:a.shape().isRequired,assetCompanyId:a.number.isRequired,currentUser:a.shape({}).isRequired};var j=o.withStyles({showMore:{textTransform:"none",backgroundColor:"transparent!important",padding:0}})(v);module.exports=j;
