(window.webpackJsonp=window.webpackJsonp||[]).push([[30],{1741:function(e,t,s){"use strict";s.r(t),s.d(t,"default",function(){return h});var a=s(16),n=s.n(a),i=s(5),o=s.n(i),r=s(28),d=s(245),p=s.n(d),c=s(937),l=s(1075);function f(e,t,s){return t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}const g=5;class h extends o.a.PureComponent{constructor(e){super(e),f(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}),f(this,"updateStateFromProps",e=>{this.setState({pdf:null,pdfPages:{},pdfPagesLoaded:{},numPages:0,loading:!0,success:!1}),p.a.getDocument(e.fileUrl).then(this.onDocumentLoad,this.onDocumentLoadError)}),f(this,"onDocumentLoad",e=>{const t=e.numPages<=g?e.numPages:g;this.setState({pdf:e,numPages:t});for(let t=1;t<=e.numPages;t++)e.getPage(t).then(this.onPageLoad)}),f(this,"onDocumentLoadError",e=>{console.log("Unable to load PDF preview: "+e),this.setState({loading:!1,success:!1})}),f(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.updateStateFromProps(this.props)}UNSAFE_componentWillReceiveProps(e){this.props.fileUrl!==e.fileUrl&&(this.updateStateFromProps(e),this.pdfPagesRendered={})}componentDidUpdate(){if(this.state.success)for(let e=0;e<this.state.numPages;e++)this.renderPDFPage(e)}render(){if(this.state.loading)return o.a.createElement("div",{className:"view-image__loading"},o.a.createElement(c.a,null));if(!this.state.success)return o.a.createElement(l.a,{fileInfo:this.props.fileInfo,fileUrl:this.props.fileUrl});const e=[];for(let t=0;t<this.state.numPages;t++)e.push(o.a.createElement("canvas",{ref:"pdfCanvas"+t,key:"previewpdfcanvas"+t})),t<this.state.numPages-1&&this.state.numPages>1&&e.push(o.a.createElement("div",{key:"previewpdfspacer"+t,className:"pdf-preview-spacer"}));return this.state.pdf.numPages>g&&e.push(o.a.createElement("a",{key:"previewpdfmorepages",href:this.props.fileUrl,className:"pdf-max-pages"},o.a.createElement(r.c,{id:"pdf_preview.max_pages",defaultMessage:"Download to read more pages"}))),o.a.createElement("div",{className:"post-code"},e)}}f(h,"propTypes",{fileInfo:n.a.object.isRequired,fileUrl:n.a.string.isRequired})}}]);
//# sourceMappingURL=30.0a542aef2dec551c3d26.js.map