(window.webpackJsonp=window.webpackJsonp||[]).push([[31],{1758:function(e,t,n){"use strict";n.r(t),n.d(t,"default",function(){return b});n(10),n(9),n(36);var a=n(8),o=n.n(a),r=n(17),s=n.n(r),i=n(554),u=n(203),p=n.n(u),d=n(831),f=n(773);function c(e){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function l(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function g(e){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function h(e,t){return(h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function m(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var P,v,y,b=function(e){function t(e){var n,a,o;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),a=this,(n=!(o=g(t).call(this,e))||"object"!==c(o)&&"function"!=typeof o?m(a):o).updateStateFromProps=n.updateStateFromProps.bind(m(m(n))),n.onDocumentLoad=n.onDocumentLoad.bind(m(m(n))),n.onDocumentLoadError=n.onDocumentLoadError.bind(m(m(n))),n.onPageLoad=n.onPageLoad.bind(m(m(n))),n.renderPDFPage=n.renderPDFPage.bind(m(m(n))),n.pdfPagesRendered={},n.state={pdf:null,pdfPages:{},pdfPagesLoaded:{},numPages:0,loading:!0,success:!1},n}var n,a,o;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&h(e,t)}(t,s.a.PureComponent),n=t,(a=[{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],n=t.getContext("2d"),a=this.state.pdfPages[e].getViewport(1);t.height=a.height,t.width=a.width;var o={canvasContext:n,viewport:a};this.state.pdfPages[e].render(o),this.pdfPagesRendered[e]=!0}}},{key:"updateStateFromProps",value:function(e){this.setState({pdf:null,pdfPages:{},pdfPagesLoaded:{},numPages:0,loading:!0,success:!1}),p.a.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 n=1;n<=e.numPages;n++)e.getPage(n).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=Object.assign({},this.state.pdfPages);t[e.pageIndex]=e;var n=Object.assign({},this.state.pdfPagesLoaded);n[e.pageIndex]=!0,this.setState({pdfPages:t,pdfPagesLoaded:n}),0===e.pageIndex&&this.setState({success:!0,loading:!1})}},{key:"render",value:function(){if(this.state.loading)return s.a.createElement("div",{className:"view-image__loading"},s.a.createElement(d.a,null));if(!this.state.success)return s.a.createElement(f.a,{fileInfo:this.props.fileInfo,fileUrl:this.props.fileUrl});for(var e=[],t=0;t<this.state.numPages;t++)e.push(s.a.createElement("canvas",{ref:"pdfCanvas"+t,key:"previewpdfcanvas"+t})),t<this.state.numPages-1&&this.state.numPages>1&&e.push(s.a.createElement("div",{key:"previewpdfspacer"+t,className:"pdf-preview-spacer"}));return this.state.pdf.numPages>5&&e.push(s.a.createElement("a",{key:"previewpdfmorepages",href:this.props.fileUrl,className:"pdf-max-pages"},s.a.createElement(i.c,{id:"pdf_preview.max_pages",defaultMessage:"Download to read more pages"}))),s.a.createElement("div",{className:"post-code"},e)}}])&&l(n.prototype,a),o&&l(n,o),t}();P=b,v="propTypes",y={fileInfo:o.a.object.isRequired,fileUrl:o.a.string.isRequired},v in P?Object.defineProperty(P,v,{value:y,enumerable:!0,configurable:!0,writable:!0}):P[v]=y}}]);
//# sourceMappingURL=31.1069e3bd3b85fc6b816e.js.map