(window.webpackJsonp=window.webpackJsonp||[]).push([[10],{2259:function(e,t,a){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var s=m(a(184)),d=m(a(281)),n=m(a(280)),o=m(a(284)),r=m(a(282)),i=m(a(283)),u=m(a(1)),f=m(a(3)),l=a(764),p=m(a(307)),c=m(a(867)),g=m(a(985));function m(e){return e&&e.__esModule?e:{default:e}}var h=function(e){function t(e){(0,n.default)(this,t);var a=(0,r.default)(this,(t.__proto__||(0,d.default)(t)).call(this,e));return a.updateStateFromProps=a.updateStateFromProps.bind(a),a.onDocumentLoad=a.onDocumentLoad.bind(a),a.onDocumentLoadError=a.onDocumentLoadError.bind(a),a.onPageLoad=a.onPageLoad.bind(a),a.renderPDFPage=a.renderPDFPage.bind(a),a.pdfPagesRendered={},a.state={pdf:null,pdfPages:{},pdfPagesLoaded:{},numPages:0,loading:!0,success:!1},a}return(0,i.default)(t,e),(0,o.default)(t,[{key:"componentDidMount",value:function(){this.updateStateFromProps(this.props)}},{key:"UNSAFE_componentWillReceiveProps",value:function(e){this.props.fileUrl!==e.fileUrl&&(this.updateStateFromProps(e),this.pdfPagesRendered={})}},{key:"componentDidUpdate",value:function(){if(this.state.success)for(var e=0;e<this.state.numPages;e++)this.renderPDFPage(e)}},{key:"renderPDFPage",value:function(e){if(!this.pdfPagesRendered[e]&&this.state.pdfPagesLoaded[e]){var t=this.refs["pdfCanvas"+e],a=t.getContext("2d"),s=this.state.pdfPages[e].getViewport(1);t.height=s.height,t.width=s.width;var d={canvasContext:a,viewport:s};this.state.pdfPages[e].render(d),this.pdfPagesRendered[e]=!0}}},{key:"updateStateFromProps",value:function(e){this.setState({pdf:null,pdfPages:{},pdfPagesLoaded:{},numPages:0,loading:!0,success:!1}),p.default.getDocument(e.fileUrl).then(this.onDocumentLoad,this.onDocumentLoadError)}},{key:"onDocumentLoad",value:function(e){var t=e.numPages<=5?e.numPages:5;this.setState({pdf:e,numPages:t});for(var a=1;a<=e.numPages;a++)e.getPage(a).then(this.onPageLoad)}},{key:"onDocumentLoadError",value:function(e){console.log("Unable to load PDF preview: "+e),this.setState({loading:!1,success:!1})}},{key:"onPageLoad",value:function(e){var t=(0,s.default)({},this.state.pdfPages);t[e.pageIndex]=e;var a=(0,s.default)({},this.state.pdfPagesLoaded);a[e.pageIndex]=!0,this.setState({pdfPages:t,pdfPagesLoaded:a}),0===e.pageIndex&&this.setState({success:!0,loading:!1})}},{key:"render",value:function(){if(this.state.loading)return f.default.createElement("div",{className:"view-image__loading"},f.default.createElement("img",{className:"loader-image",src:c.default}));if(!this.state.success)return f.default.createElement(g.default,{fileInfo:this.props.fileInfo,fileUrl:this.props.fileUrl});for(var e=[],t=0;t<this.state.numPages;t++)e.push(f.default.createElement("canvas",{ref:"pdfCanvas"+t,key:"previewpdfcanvas"+t})),t<this.state.numPages-1&&this.state.numPages>1&&e.push(f.default.createElement("div",{key:"previewpdfspacer"+t,className:"pdf-preview-spacer"}));return this.state.pdf.numPages>5&&e.push(f.default.createElement("a",{key:"previewpdfmorepages",href:this.props.fileUrl,className:"pdf-max-pages"},f.default.createElement(l.FormattedMessage,{id:"pdf_preview.max_pages",defaultMessage:"Download to read more pages"}))),f.default.createElement("div",{className:"post-code"},e)}}]),t}(f.default.PureComponent);h.propTypes={fileInfo:u.default.object.isRequired,fileUrl:u.default.string.isRequired},t.default=h}}]);
//# sourceMappingURL=10.3efd39b3683bd7e15460.js.map