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