"use strict";(self.webpackChunkmattermost_webapp=self.webpackChunkmattermost_webapp||[]).push([[1500],{21500:(e,t,s)=>{s.r(t),s.d(t,{default:()=>u});var i=s(23615),n=s.n(i),a=(s(61418),s(14078),s(48410),s(92189),s(66726)),r=s.n(a),o=s(84390),l=s.n(o),d=s(47407),c=s(84273),p=s(26337),f=s(41894);function h(e,t,s){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var s=e[Symbol.toPrimitive];if(void 0!==s){var i=s.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}class u extends l().PureComponent{constructor(e){super(e),h(this,"parentNode",null),h(this,"pdfCanvasRef",{}),h(this,"downloadFile",(e=>{const t=this.props.fileInfo.link||(0,d.gN)(this.props.fileInfo.id);e.preventDefault(),window.location.href=t})),h(this,"isInViewport",(e=>{var t,s,i,n;const a=e.getBoundingClientRect(),r=null!==(t=null===(s=this.container.current)||void 0===s?void 0:s.scrollTop)&&void 0!==t?t:0,o=r+(null!==(i=null===(n=this.parentNode)||void 0===n?void 0:n.clientHeight)&&void 0!==i?i:0);return a.top>=r&&a.top<=o||a.bottom>=r&&a.bottom<=o||a.top<=r&&a.bottom>=o})),h(this,"renderPDFPage",(async e=>{const t=this.pdfCanvasRef["pdfCanvasRef-".concat(e)].current;if(!t)return;if(e>=3&&!this.isInViewport(t))return;if(this.pdfPagesRendered[e])return;const s=await this.loadPage(this.state.pdf,e),i=t.getContext("2d"),n=s.getViewport({scale:this.props.scale});t.height=n.height,t.width=n.width;const a={canvasContext:i,viewport:n};await s.render(a).promise,this.pdfPagesRendered[e]=!0})),h(this,"getPdfDocument",(async()=>{try{const e=await Promise.all([s.e(7803),s.e(9707)]).then(s.t.bind(s,47803,23)),t=await s.e(5456).then(s.t.bind(s,65456,23));e.GlobalWorkerOptions.workerSrc=t;const i=await e.getDocument({url:this.props.fileUrl,cMapUrl:(0,f.fO)()+"/static/cmaps/",cMapPacked:!0}).promise;this.onDocumentLoad(i)}catch(e){this.onDocumentLoadError(e)}})),h(this,"onDocumentLoad",(e=>{this.setState({pdf:e,numPages:e.numPages});for(let t=0;t<e.numPages;t++)this.pdfCanvasRef["pdfCanvasRef-".concat(t)]=l().createRef();this.setState({loading:!1,success:!0})})),h(this,"onDocumentLoadError",(e=>{console.log("Unable to load PDF preview: "+e),this.setState({loading:!1,success:!1})})),h(this,"loadPage",(async(e,t)=>{if(this.state.pdfPagesLoaded[t])return this.state.pdfPages[t];const s=await e.getPage(t+1),i=Object.assign({},this.state.pdfPages);i[t]=s;const n=Object.assign({},this.state.pdfPagesLoaded);return n[t]=!0,this.setState({pdfPages:i,pdfPagesLoaded:n}),s})),h(this,"handleScroll",r()((()=>{if(this.state.success)for(let e=0;e<this.state.numPages;e++)this.renderPDFPage(e)}),100)),this.pdfPagesRendered={},this.container=l().createRef(),this.state={pdf:null,pdfPages:[],pdfPagesLoaded:{},numPages:0,loading:!0,success:!1,prevFileUrl:""}}componentDidMount(){var e;this.getPdfDocument(),this.container.current&&(this.parentNode=this.container.current.parentElement,null===(e=this.parentNode)||void 0===e||e.addEventListener("scroll",this.handleScroll))}componentWillUnmount(){this.parentNode&&this.parentNode.removeEventListener("scroll",this.handleScroll)}static getDerivedStateFromProps(e,t){return e.fileUrl!==t.prevFileUrl?{pdf:null,pdfPages:{},pdfPagesLoaded:{},numPages:0,loading:!0,success:!1,prevFileUrl:e.fileUrl}:null}componentDidUpdate(e,t){if(this.props.fileUrl!==e.fileUrl&&(this.getPdfDocument(),this.pdfPagesRendered={}),this.props.scale!==e.scale&&(this.pdfPagesRendered={},this.state.success))for(let e=0;e<this.state.numPages;e++)this.renderPDFPage(e);if(!t.success&&this.state.success)for(let e=0;e<this.state.numPages;e++)this.renderPDFPage(e)}render(){if(this.state.loading)return l().createElement("div",{ref:this.container,className:"view-image__loading"},l().createElement(p.Z,null));if(!this.state.success)return l().createElement(c.Z,{fileInfo:this.props.fileInfo,fileUrl:this.props.fileUrl});const e=[];for(let t=0;t<this.state.numPages;t++)e.push(l().createElement("canvas",{ref:this.pdfCanvasRef["pdfCanvasRef-".concat(t)],key:"previewpdfcanvas"+t})),t<this.state.numPages-1&&this.state.numPages>1&&e.push(l().createElement("div",{key:"previewpdfspacer"+t,className:"pdf-preview-spacer"}));return l().createElement("div",{ref:this.container,className:"post-code",onClick:this.props.handleBgClose},e)}}h(u,"propTypes",{fileUrl:n().string.isRequired,scale:n().number.isRequired,handleBgClose:n().func.isRequired})}}]);
//# sourceMappingURL=1500.a0655e7f30ccaf2b7f6f.js.map