/*!
 * Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see https://ckeditor.com/legal/ckeditor-oss-license
 */
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.CKEditor5=r():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.wproofreaderAdapter=r())}(self,(()=>(()=>{"use strict";var e={d:(r,o)=>{for(var t in o)e.o(o,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:o[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)},r={};e.d(r,{default:()=>o});!function(e,r){r.CKEditor5PremiumFeaturesWProofreader={validate:()=>new Promise((r=>{e.get("/ckeditor5-premium-features-wproofreader/validate-service-id").done((function(e){r({valid:e.valid})})).catch((e=>{let o=e.responseJSON;r({valid:o.valid,usage_limit_error:o.usage_limit_error??null})}))}))}}(jQuery,Drupal);const o={WProofreaderAdapter:class{constructor(e){this.editor=e}afterInit(){this._validatePermission(),this._validateKey()}_validateKey(){Drupal.CKEditor5PremiumFeaturesWProofreader.validate().then((e=>{if(!e.valid){this._disablePlugin();let r="wproofreader-service-id-error";e.usage_limit_error&&(r="wproofreader-usage-limit-error"),this._dispatchErrorEvent(r)}}))}_validatePermission(){const e=this.editor.config._config.wproofreader.cke5?.validPermission;e||(this._disablePlugin(),this._dispatchErrorEvent("wproofreader-permission-error"))}_disablePlugin(){this.editor.plugins.get("WProofreader").forceDisabled("load-error"),this.editor.commands.get("WProofreaderToggle").forceDisabled("load-error"),this.editor.commands.get("WProofreaderSettings").forceDisabled("load-error"),this.editor.commands.get("WProofreaderDialog").forceDisabled("load-error")}_dispatchErrorEvent(e){var r=new ErrorEvent("error",{error:new Error(e)});dispatchEvent(r)}}};return r=r.default})()));