webpackJsonp([24],{1874:function(e,t,a){"use strict";function s(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var d=a(169),n=s(d),o=a(259),r=s(o),i=a(258),u=s(i),f=a(262),l=s(f),p=a(260),c=s(p),g=a(261),m=s(g),h=a(22),P=s(h),v=a(14),D=s(v),L=a(749),y=a(287),k=s(y),w=a(851),E=s(w),_=a(952),F=s(_),S=function(e){function t(e){(0,u.default)(this,t);var a=(0,c.default)(this,(t.__proto__||(0,r.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,m.default)(t,e),(0,l.default)(t,[{key:"componentDidMount",value:function(){this.updateStateFromProps(this.props)}},{key:"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}),k.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,n.default)({},this.state.pdfPages);t[e.pageIndex]=e;var a=(0,n.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 D.default.createElement("div",{className:"view-image__loading"},D.default.createElement("img",{className:"loader-image",src:E.default}));if(!this.state.success)return D.default.createElement(F.default,{fileInfo:this.props.fileInfo,fileUrl:this.props.fileUrl});for(var e=[],t=0;t<this.state.numPages;t++)e.push(D.default.createElement("canvas",{ref:"pdfCanvas"+t,key:"previewpdfcanvas"+t})),t<this.state.numPages-1&&this.state.numPages>1&&e.push(D.default.createElement("div",{key:"previewpdfspacer"+t,className:"pdf-preview-spacer"}));return this.state.pdf.numPages>5&&e.push(D.default.createElement("a",{key:"previewpdfmorepages",href:this.props.fileUrl,className:"pdf-max-pages"},D.default.createElement(L.FormattedMessage,{id:"pdf_preview.max_pages",defaultMessage:"Download to read more pages"}))),D.default.createElement("div",{className:"post-code"},e)}}]),t}(D.default.PureComponent);S.propTypes={fileInfo:P.default.object.isRequired,fileUrl:P.default.string.isRequired},t.default=S}});
//# sourceMappingURL=24.7192aac9541b12a5f543.js.map