/*!
 * PSPDFKit for Web 2021.4.1 (https://pspdfkit.com/web)
 * 
 * Copyright (c) 2016-2019 PSPDFKit GmbH. All rights reserved.
 * 
 * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
 * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
 * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
 * This notice may not be removed from this file.
 * 
 * PSPDFKit uses several open source third-party components: https://pspdfkit.com/acknowledgements/web/
 */
(window.webpackJsonpPSPDFKit=window.webpackJsonpPSPDFKit||[]).push([[61],{725:function(t,e,a){"use strict";a.r(e),a.d(e,"RESTProvider",(function(){return y}));var s=a(70),o=a.n(s),i=a(1),r=a.n(i),n=a(4),c=a(3),d=a(42),l=a(133);class h extends(n.e({alreadyLoadedPages:Object(n.b)(),serverURL:null,authPayload:null,isLoaded:!1,isFormsEnabled:!0,loadBookmarksPromise:null,ignoredFormFieldNames:null})){}var u=a(188),m=a(250),b=a(7);function k(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),a.push.apply(a,s)}return a}class y{constructor(t,e,{isFormsEnabled:a}){r()(this,"canCreateBackendOrphanWidgets",!0),r()(this,"setDocumentHandleConflictCallback",(()=>{})),this.state=new h({serverURL:t,authPayload:e,isFormsEnabled:a})}async load(){return this.state=this.state.set("isLoaded",!0),this.state.isFormsEnabled&&await this._initializeFormFieldValues(),this}destroy(){}setReadStateCallbacks(t){this._readStateCallbacks=t}setAnnotationCallbacks(t){this.annotationCallbacks=t}setBookmarkCallbacks(t){this.bookmarkCallbacks=t}setFormFieldValueCallbacks(t){this.formFieldValueCallbacks=t}async createAnnotation(t,e){this._verifyLoaded();const a=Object(d.o)(t),{id:s}=a,i={id:s,content:o()(a,["id"])};await this._request("/annotations","POST",i).then((t=>{if(200!==t.status)throw new c.a("PSPDFKit Server returned an error, when saving an annotation.");t.json().then((t=>{if("attachment_missing"===t.error){const t=function(t,e){const a=new FormData;return a.append("annotation",JSON.stringify(t)),e.forEach(((t,e)=>{e&&t.data&&a.append(e,t.data)})),a}(i,e);return this._request("/annotations","POST",t).then((t=>t.json()))}return t}))}))}async updateAnnotation(t){this._verifyLoaded();const e=Object(d.o)(t),{id:a}=e,s=o()(e,["id"]);await this._request(`/annotations/${a}`,"PUT",{id:a,content:s})}async deleteAnnotation(t){this._verifyLoaded(),await this._request(`/annotations/${t.id}`,"DELETE")}async createBookmark(t){this._verifyLoaded(),await this.loadBookmarks();const e=Object(l.b)(t),{id:a}=e,s=o()(e,["id"]);if(200!==(await this._request("/bookmarks","POST",{id:a,content:s})).status)throw new c.a("PSPDFKit Server returned an error, when saving an bookmark.")}async updateBookmark(t){this._verifyLoaded(),await this.loadBookmarks();const e=Object(l.b)(t),{id:a}=e,s=o()(e,["id"]);await this._request(`/bookmarks/${a}`,"PUT",{id:a,content:s})}async deleteBookmark(t){this._verifyLoaded(),await this.loadBookmarks(),await this._request(`/bookmarks/${t}`,"DELETE")}async setFormFieldValue(t){this._verifyLoaded();const e={id:Object(u.b)(t),content:Object(d.s)(t)};await this._request("/form-field-values","POST",{formFieldValues:[e]})}async createFormFieldValue(){}async deleteFormFieldValue(){}async loadAnnotationsForPageIndex(t){if(this._verifyLoaded(),this.state.alreadyLoadedPages.has(t))await this.state.alreadyLoadedPages.get(t);else try{const e=this._request(`/page-${t}-annotations`,"GET").then((t=>t.json())).catch((t=>{throw t}));this.state=this.state.setIn(["alreadyLoadedPages",t],e);const a=await e;this.state=this.state.setIn(["alreadyLoadedPages",t],Promise.resolve());const s=Object(n.a)().withMutations((t=>{a.annotations.map((e=>{try{t.push(Object(d.c)(e.id,e.content))}catch(t){Object(c.j)(`Skipped creating annotation #${e.id} from payload because an error occurred while deserializing.`,e.content),Object(c.j)(t)}}))}));s.size>0&&(Object(b.a)(this.annotationCallbacks),this.annotationCallbacks.createAnnotations(s,Object(n.b)(),m.a))}catch(t){this._handleError(t,"annotations")}}async loadBookmarks(){if(this._verifyLoaded(),this.state.loadBookmarksPromise)await this.state.loadBookmarksPromise;else try{const t=this._request("/bookmarks","GET").then((t=>t.json())).then((t=>t.data)).catch((t=>{throw t}));this.state=this.state.set("loadBookmarksPromise",t);const e=await t;this.state=this.state.set("loadBookmarksPromise",Promise.resolve()),Object(b.a)(Array.isArray(e.bookmarks),"Unexpected reply from bookmarks endpoint.");const a=Object(n.a)().withMutations((t=>{e.bookmarks.forEach((e=>{try{t.push(Object(l.a)(e.id,e.content))}catch(t){Object(c.j)(`Skipped creating bookmark #${e.id} from payload because an error occurred while deserializing.`,e),Object(c.j)(t)}}))}));a.size>0&&(Object(b.a)(this.bookmarkCallbacks),this.bookmarkCallbacks.createBookmarks(a,m.a))}catch(t){this._handleError(t,"bookmarks")}}async syncChanges(){}async _initializeFormFieldValues(){const t=await this._request("/form-field-values","GET"),e=await t.json();Object(b.a)(Array.isArray(e.formFieldValues),"Unexpected reply from form-values endpoint.");const a=Object(n.a)(e.formFieldValues.map((({content:t})=>{try{return Object(d.f)(t)}catch(e){return Object(c.j)(`Skipped form field value ${t.name} from payload because an error occurred while deserializing.`,t),Object(c.j)(e),null}})).filter(Boolean));Object(b.a)(this.formFieldValueCallbacks),this.state.ignoredFormFieldNames&&this.state.ignoredFormFieldNames.size?this.formFieldValueCallbacks.setFormFieldValues(a.filter((t=>{var e;return!(null===(e=this.state.ignoredFormFieldNames)||void 0===e?void 0:e.includes(t.name))}))):this.formFieldValueCallbacks.setFormFieldValues(a)}_handleError(t,e){Object(c.i)(`Loading or updating ${e} failed:\n\n${t.message}`)}_request(t,e,a){Object(b.a)(null!=this.state.authPayload,"Cannot call request without authPayload");const s=a instanceof FormData||"object"!=typeof a?null:{"Content-Type":"application/json"},o=function(t){for(var e=1;e<arguments.length;e++){var a=null!=arguments[e]?arguments[e]:{};e%2?k(Object(a),!0).forEach((function(e){r()(t,e,a[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):k(Object(a)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))}))}return t}({"X-PSPDFKit-Token":this.state.authPayload.token,"PSPDFKit-Platform":"web","PSPDFKit-Version":"protocol=4, client=2021.4.1, client-git=960843e0b3"},s);return fetch(`${this.state.serverURL}${t}`,{method:e,headers:o,body:a instanceof FormData?a:"object"==typeof a?JSON.stringify(a):void 0,credentials:"include"})}_verifyLoaded(){if(!this.state.isLoaded)throw new Error("not loaded")}setIgnoredFormFieldNames(t){this.state=this.state.set("ignoredFormFieldNames",t)}}}}]);