!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CKEditor5=t():(e.CKEditor5=e.CKEditor5||{},e.CKEditor5.mediaExpired=t())}(self,(()=>(()=>{var e={"ckeditor5/src/core.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/core.js")},"ckeditor5/src/ui.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/ui.js")},"ckeditor5/src/widget.js":(e,t,i)=>{e.exports=i("dll-reference CKEditor5.dll")("./src/widget.js")},"dll-reference CKEditor5.dll":e=>{"use strict";e.exports=CKEditor5.dll}},t={};function i(r){var d=t[r];if(void 0!==d)return d.exports;var a=t[r]={exports:{}};return e[r](a,a.exports,i),a.exports}i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r={};return(()=>{"use strict";i.d(r,{default:()=>l});var e=i("ckeditor5/src/core.js");i("ckeditor5/src/widget.js");function t(e){return!!e&&e.is("element","drupalMedia")}class d extends e.Command{refresh(){const{editor:e}=this,{selection:i}=e.model.document;let r=i.getSelectedElement();r||(r=function(e){const i=e.getSelectedElement();return t(i)?i:e.getFirstPosition().findAncestor("drupalMedia")}(i)),this.isEnabled=t(r)&&r.hasAttribute("mediaIsExpired")&&r.getAttribute("mediaIsExpired")}execute(e={}){const{mediaIsExpired:t}=e,{editor:i}=this;i.model.change((e=>{const r=i.model.document.selection.getSelectedElement();e.setAttribute("mediaIsExpired",t,r)}))}}class a extends e.Plugin{static get pluginName(){return"MediaExpiredRepository"}init(){this._data=new WeakMap}getRevisionMetadata(e){if(this._data.get(e))return new Promise((t=>{t(this._data.get(e))}));const{mediaExpiredCheckUrl:t,acquiaDamCsrfToken:i}=this.editor.config.get("drupalMedia"),r=e.getAttribute("drupalMediaEntityUuid");return fetch(`${t}?uuid=${r}`,{headers:{"X-Drupal-AcquiaDam-CSRF-Token":i}}).then((e=>e.json())).then((t=>(this._data.set(e,t),t)))}refreshModelMetadata(e){return this._data.delete(e),this.getRevisionMetadata(e)}}var s=i("ckeditor5/src/ui.js");class o extends e.Plugin{static get requires(){return["DrupalMediaEditing",a]}static get pluginName(){return"MediaExpiredEditing"}init(){const{editor:e}=this;e.model.schema.extend("drupalMedia",{allowAttributes:["mediaIsExpired"]});const{conversion:t}=e;t.for("upcast").add((t=>{t.on("element:drupal-media",((t,i)=>{const[r]=i.modelRange.getItems();this.editor.plugins.get("MediaExpiredRepository").getRevisionMetadata(r).then((t=>{r&&e.model.enqueueChange({isUndoable:!1},(e=>{e.setAttribute("mediaIsExpired",t.isExpired,r)}))}))}),{priority:"lowest"})})),t.for("editingDowncast").add((t=>{t.on("attribute:mediaIsExpired",((t,i)=>{if(null===i.attributeOldValue||i.attributeOldValue===i.attributeNewValue)return;this.editor.plugins.get("MediaExpiredRepository").refreshModelMetadata(i.item).then((t=>{i.item&&e.model.enqueueChange({isUndoable:!1},(e=>{e.setAttribute("mediaIsExpired",t.isExpired,i.item)}))}))})),t.on("attribute:mediaIsExpired",((e,t,i)=>{const{writer:r,mapper:d}=i,a=d.toViewElement(t.item);if(!1===t.attributeNewValue){const e=Array.from(a.getChildren()).find((e=>e.getCustomProperty("mediaExpiredWarning")));return void(e&&r.remove(e))}const o=Drupal.t("This media item is expired. Expired media is not visible to content viewers, replace the media."),n=new s.Template({tag:"span",children:[{tag:"span",attributes:{class:"drupal-media__mediaexpired-alert-icon","data-cke-tooltip-text":o}}]}).render(),l=r.createRawElement("div",{class:"drupal-media__mediaexpired-alert"},((e,t)=>{t.setContentOf(e,n.outerHTML)}));r.setCustomProperty("mediaExpiredWarning",!0,l),r.insert(r.createPositionAt(a,0),l)}),{priority:"low"})})),e.commands.add("updateMediaExpired",new d(e))}}class n extends e.Plugin{static get requires(){return[o]}static get pluginName(){return"MediaExpired"}}const l={MediaExpired:n}})(),r=r.default})()));