"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("./mode-island-constants.cjs"),l=require("./validators.cjs"),r=require("./utils.cjs"),o=require("vue"),u=require("../../_plugin-vue_export-helper-BRilXfQE.cjs"),c={name:"DtModeIsland",compatConfig:{MODE:3},provide(){return{dtModeIslandMode:()=>this.computedMode}},inject:{parentModeIslandMode:{from:"dtModeIslandMode",default:null}},inheritAttrs:!1,props:{as:{type:String,default:"div"},mode:{type:String,default:d.DT_MODE_ISLAND_TYPES.INVERTED,validator:l.modeValidator}},data(){return{currentContrast:r.getRootContrast(),contrastObserver:null,modeObserver:null,elementRef:null,calculatedMode:null}},computed:{isInverted(){return this.mode===d.DT_MODE_ISLAND_TYPES.INVERTED},invertedAttribute(){return this.isInverted?"":null},computedMode(){return this.mode===d.DT_MODE_ISLAND_TYPES.LIGHT||this.mode===d.DT_MODE_ISLAND_TYPES.DARK?this.mode:this.mode===d.DT_MODE_ISLAND_TYPES.INVERTED&&this.calculatedMode?this.calculatedMode:this.calculateInvertedMode()}},beforeCreate(){if(this.$attrs&&this.$attrs["data-dt-brand"])throw new Error("[DtModeIsland] The data-dt-brand attribute is not allowed on mode islands. Brand should only be set at the root level.")},mounted(){this.elementRef=this.$el,this.setupContrastObserver(),this.isInverted&&(this.calculatedMode=this.calculateInvertedMode(),this.setupModeObserver()),this.currentContrast=r.getRootContrast()},beforeUnmount(){this.contrastObserver&&(this.contrastObserver.disconnect(),this.contrastObserver=null),this.modeObserver&&(this.modeObserver.disconnect(),this.modeObserver=null)},methods:{calculateInvertedMode(){if(this.parentModeIslandMode){const e=typeof this.parentModeIslandMode=="function"?this.parentModeIslandMode():this.parentModeIslandMode;return r.getOppositeMode(e)}if(this.elementRef){const e=r.findParentMode(this.elementRef);return r.getOppositeMode(e)}return r.getOppositeMode(r.getRootMode())},setupContrastObserver(){this.contrastObserver=new MutationObserver(e=>{for(const t of e)t.type==="attributes"&&t.attributeName==="data-dt-contrast"&&(this.currentContrast=r.getRootContrast())}),this.contrastObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["data-dt-contrast"]})},setupModeObserver(){var s;const e={attributes:!0,attributeFilter:["data-dt-mode"],subtree:!1};this.modeObserver=new MutationObserver(a=>{for(const n of a)n.type==="attributes"&&n.attributeName==="data-dt-mode"&&(this.calculatedMode=this.calculateInvertedMode())}),this.modeObserver.observe(document.documentElement,e);let t=(s=this.elementRef)==null?void 0:s.parentElement;for(;t;)t.hasAttribute("data-dt-mode")&&this.modeObserver.observe(t,e),t=t.parentElement}}};function m(e,t,s,a,n,i){return o.openBlock(),o.createBlock(o.resolveDynamicComponent(s.as),o.mergeProps({class:"d-mode-island"},e.$attrs,{"data-dt-mode":i.computedMode,"data-mode-island-inverted":i.invertedAttribute,"data-dt-contrast":n.currentContrast}),{default:o.withCtx(()=>[o.renderSlot(e.$slots,"default")]),_:3},16,["data-dt-mode","data-mode-island-inverted","data-dt-contrast"])}const h=u._(c,[["render",m]]);exports.default=h;
//# sourceMappingURL=mode-island.cjs.map
