import e from"@babel/runtime/helpers/slicedToArray";import{useState as n,useRef as t,useMemo as o,useEffect as r}from"react";import i from"prop-types";import{sortBy as s,noop as m}from"lodash";import p from"moment";import{makeStyles as c,Typography as a}from"@material-ui/core";import l from"../../Comment/index.js";import d from"../../CommentLoader.js";import C from"../../CommentInput/index.js";import{postFeedItemComment as u}from"../../../clients/jsonApi/index.js";import"../../DevCenter/DevCenterAppContainer/components/AppActions/AppActions.css.js";import{jsxs as v,jsx as f}from"react/jsx-runtime";import"../../DevCenter/DevCenterAppContainer/components/AppSettingsDialog/AppSettingsDialog.js";import"../../DevCenter/DevCenterAppContainer/components/AppSettingsDialog/components/RemoveAppButton.js";import"../../DevCenter/DevCenterAppContainer/components/AppSettingsDialog/components/SettingsAccordion.js";import"../../DevCenter/DevCenterAppContainer/components/AnnotationsButton/AnnotationsButton.js";import"../../DevCenter/DevCenterAppContainer/components/NonPriorityMenus/NonPriorityMenus.js";import"../../DevCenter/DevCenterAppContainer/components/FullscreenButton/FullscreenButton.js";import"../../DevCenter/DevCenterAppContainer/components/AppInfoMessage/AppInfoMessage.js";import"../../DevCenter/DevCenterAppContainer/components/DevCenterAppView/DevCenterAppView.js";import"../../DevCenter/DevCenterAppContainer/components/DcFullscreenElemsCoordinatorProvider/DcFullscreenElemsCoordinatorProvider.js";import"../../DevCenter/DevCenterAppContainer/components/DcFullscreenElemsCoordinatorProvider/IsInsideDcFullscreenElemProvider.js";import{useIsInsideDcApp as D}from"../../DevCenter/DevCenterAppContainer/components/IsInsideDcAppProvider/IsInsideDcAppProvider.js";import{isNativeDetected as A}from"../../../utils/mobileDetect.js";var g=c({showMore:{cursor:"pointer"},feedCommentsContainer:{padding:"0 16px 0 24px"},feedCommentsList:{marginTop:24},feedCommentsListContent:{height:function(e){var n=e.commentsListHeight;return n&&n-8},overflow:function(e){return e.commentsListHeight&&"scroll"}},feedCommentsListContentWrapper:{position:"relative"},gradient:{position:"absolute",bottom:0,left:0,width:"100%",height:16,background:function(e){var n=e.isInsideDcApp;return"linear-gradient(180deg, rgba(61, 61, 61, 0) 0%, ".concat(n?"#414141":"3b3b3b"," 100%)")}}});function h(i){var c,h=i.openCommentInput,j=i.openCommentList,I=i.feedItem,b=i.currentUser,y=I.comments,L=y.length,P=L>3,x=n(!1),F=e(x,2),N=F[0],w=F[1],M=n(!1),S=e(M,2),B=S[0],H=S[1],R=n(!1),k=e(R,2),E=k[0],U=k[1],_=n(null),q=e(_,2),T=q[0],V=q[1],W=t(),z=t(),K=o((function(){var e=s(I.comments,(function(e){return-p(e.created_at).unix()}));return E?E&&!B?e.slice(0,5):E&&B?e:[]:e.slice(0,3)}),[y,B,E]);r((function(){if(5===K.length&&!T){var e=z.current.clientHeight;V(e),H(!0)}T&&!E&&(V(null),H(!1))}),[K.length,T,E]);var G=D(),J=g({commentsListHeight:T,isAllCommentsVisibleKeyPressed:E,isInsideDcApp:G});return v("div",{className:(h||!!L)&&J.feedCommentsContainer,children:[h&&!A&&f(C,{inputRef:W,postComment:function(e){u(I.id,e)},setIsPosting:w,companyId:I.company_id,autoFocus:!1,currentUser:b,parentId:"".concat(I.id,"-").concat(null===(c=I.comments)||void 0===c?void 0:c.size)}),j&&v("div",{className:J.feedCommentsList,children:[f("div",{className:J.feedCommentsListContentWrapper,children:v("div",{className:J.feedCommentsListContent,ref:z,children:[K.map((function(e){return f(l,{comment:e,handleDeleteCallback:m,patchCommentCallback:m,companyId:I.company_id,currentUser:b},e.id)})),T&&f("div",{className:J.gradient})]})}),P&&f(a,{variant:"caption",color:"primary","data-testid":"".concat("FeedComments","_viewMoreComments"),className:J.showMore,onClick:function(){U(!E)},children:E?"Hide older comments":"See all comments"})]}),N&&f(d,{})]})}h.propTypes={openCommentInput:i.bool.isRequired,feedItem:i.shape().isRequired,currentUser:i.shape().isRequired};export{h as default};
