"use strict";var e=require("@babel/runtime/helpers/slicedToArray"),n=require("react"),t=require("prop-types"),r=require("lodash"),o=require("moment"),s=require("@material-ui/core"),i=require("../../Comment/index.js"),p=require("../../CommentLoader.js"),a=require("../../CommentInput/index.js"),c=require("../../../clients/jsonApi/index.js");require("../../DevCenter/DevCenterAppContainer/components/AppActions/AppActions.css.js");var m=require("react/jsx-runtime");require("../../DevCenter/DevCenterAppContainer/components/AppSettingsDialog/AppSettingsDialog.js"),require("../../DevCenter/DevCenterAppContainer/components/AppSettingsDialog/components/RemoveAppButton.js"),require("../../DevCenter/DevCenterAppContainer/components/AppSettingsDialog/components/SettingsAccordion.js"),require("../../DevCenter/DevCenterAppContainer/components/AnnotationsButton/AnnotationsButton.js"),require("../../DevCenter/DevCenterAppContainer/components/NonPriorityMenus/NonPriorityMenus.js"),require("../../DevCenter/DevCenterAppContainer/components/FullscreenButton/FullscreenButton.js"),require("../../DevCenter/DevCenterAppContainer/components/AppInfoMessage/AppInfoMessage.js"),require("../../DevCenter/DevCenterAppContainer/components/DevCenterAppView/DevCenterAppView.js"),require("../../DevCenter/DevCenterAppContainer/components/DcFullscreenElemsCoordinatorProvider/DcFullscreenElemsCoordinatorProvider.js"),require("../../DevCenter/DevCenterAppContainer/components/DcFullscreenElemsCoordinatorProvider/IsInsideDcFullscreenElemProvider.js");var u=require("../../DevCenter/DevCenterAppContainer/components/IsInsideDcAppProvider/IsInsideDcAppProvider.js"),l=require("../../../utils/mobileDetect.js");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var C=d(e),v=d(t),f=d(o),D=s.makeStyles({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 A(e){var t,o=e.openCommentInput,d=e.openCommentList,v=e.feedItem,A=e.currentUser,g=v.comments,j=g.length,q=j>3,h=n.useState(!1),I=C.default(h,2),x=I[0],y=I[1],b=n.useState(!1),L=C.default(b,2),S=L[0],P=L[1],F=n.useState(!1),N=C.default(F,2),M=N[0],w=N[1],R=n.useState(null),B=C.default(R,2),k=B[0],E=B[1],H=n.useRef(),T=n.useRef(),U=n.useMemo((function(){var e=r.sortBy(v.comments,(function(e){return-f.default(e.created_at).unix()}));return M?M&&!S?e.slice(0,5):M&&S?e:[]:e.slice(0,3)}),[g,S,M]);n.useEffect((function(){if(5===U.length&&!k){var e=T.current.clientHeight;E(e),P(!0)}k&&!M&&(E(null),P(!1))}),[U.length,k,M]);var _=u.useIsInsideDcApp(),V=D({commentsListHeight:k,isAllCommentsVisibleKeyPressed:M,isInsideDcApp:_});return m.jsxs("div",{className:(o||!!j)&&V.feedCommentsContainer,children:[o&&!l.isNativeDetected&&m.jsx(a,{inputRef:H,postComment:function(e){c.postFeedItemComment(v.id,e)},setIsPosting:y,companyId:v.company_id,autoFocus:!1,currentUser:A,parentId:"".concat(v.id,"-").concat(null===(t=v.comments)||void 0===t?void 0:t.size)}),d&&m.jsxs("div",{className:V.feedCommentsList,children:[m.jsx("div",{className:V.feedCommentsListContentWrapper,children:m.jsxs("div",{className:V.feedCommentsListContent,ref:T,children:[U.map((function(e){return m.jsx(i,{comment:e,handleDeleteCallback:r.noop,patchCommentCallback:r.noop,companyId:v.company_id,currentUser:A},e.id)})),k&&m.jsx("div",{className:V.gradient})]})}),q&&m.jsx(s.Typography,{variant:"caption",color:"primary","data-testid":"".concat("FeedComments","_viewMoreComments"),className:V.showMore,onClick:function(){w(!M)},children:M?"Hide older comments":"See all comments"})]}),x&&m.jsx(p,{})]})}A.propTypes={openCommentInput:v.default.bool.isRequired,feedItem:v.default.shape().isRequired,currentUser:v.default.shape().isRequired},module.exports=A;
