(window.webpackJsonp=window.webpackJsonp||[]).push([[29],{2197:function(e,t,s){"use strict";s.r(t),s.d(t,"default",(function(){return u}));s(204);var a=s(133),n=s.n(a),i=s(4),r=s.n(i),o=s(1213),d=s(306),p=s.n(d),l=s(1266),c=s(1252),f=s(1405);function g(e,t,s){return t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}class u extends r.a.PureComponent{constructor(e){super(e),g(this,"renderPDFPage",e=>{if(this.pdfPagesRendered[e]||!this.state.pdfPagesLoaded[e])return;const t=this.refs["pdfCanvas"+e],s=t.getContext("2d"),a=this.state.pdfPages[e].getViewport(1);t.height=a.height,t.width=a.width;const n={canvasContext:s,viewport:a};this.state.pdfPages[e].render(n),this.pdfPagesRendered[e]=!0}),g(this,"getPdfDocument",()=>{p.a.getDocument(this.props.fileUrl).then(this.onDocumentLoad).catch(this.onDocumentLoadError)}),g(this,"onDocumentLoad",e=>{const t=e.numPages<=5?e.numPages:5;this.setState({pdf:e,numPages:t});for(let t=1;t<=e.numPages;t++)e.getPage(t).then(this.onPageLoad)}),g(this,"onDocumentLoadError",e=>{console.log("Unable to load PDF preview: "+e),this.setState({loading:!1,success:!1})}),g(this,"onPageLoad",e=>{const t=Object.assign({},this.state.pdfPages);t[e.pageIndex]=e;const s=Object.assign({},this.state.pdfPagesLoaded);s[e.pageIndex]=!0,this.setState({pdfPages:t,pdfPagesLoaded:s}),0===e.pageIndex&&this.setState({success:!0,loading:!1})}),this.pdfPagesRendered={},this.state={pdf:null,pdfPages:{},pdfPagesLoaded:{},numPages:0,loading:!0,success:!1}}componentDidMount(){this.getPdfDocument()}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){if(this.props.fileUrl!==e.fileUrl&&(this.getPdfDocument(),this.pdfPagesRendered={}),this.state.success)for(let e=0;e<this.state.numPages;e++)this.renderPDFPage(e)}render(){if(this.state.loading)return r.a.createElement("div",{className:"view-image__loading"},r.a.createElement(c.a,null));if(!this.state.success)return r.a.createElement(f.a,{fileInfo:this.props.fileInfo,fileUrl:this.props.fileUrl});const e=[];for(let t=0;t<this.state.numPages;t++)e.push(r.a.createElement("canvas",{ref:"pdfCanvas"+t,key:"previewpdfcanvas"+t})),t<this.state.numPages-1&&this.state.numPages>1&&e.push(r.a.createElement("div",{key:"previewpdfspacer"+t,className:"pdf-preview-spacer"}));if(this.state.pdf.numPages>5){const t=this.props.fileInfo.link||Object(l.getFileDownloadUrl)(this.props.fileInfo.id);e.push(r.a.createElement("a",{key:"previewpdfmorepages",href:t,className:"pdf-max-pages"},r.a.createElement(o.a,{id:"pdf_preview.max_pages",defaultMessage:"Download to read more pages"})))}return r.a.createElement("div",{className:"post-code"},e)}}g(u,"propTypes",{fileInfo:n.a.object.isRequired,fileUrl:n.a.string.isRequired})}}]);
//# sourceMappingURL=29.965a4fde7150f3d075a7.js.map