/*
    *
    * Wijmo Library 5.20182.500
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const wjcMeta=require("wijmo/wijmo.meta"),wjcCore=require("wijmo/wijmo"),wjcSelfRef=require("wijmo/wijmo.webcomponents.base");var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.webcomponents=window.wijmo.webcomponents||{},window.wijmo.webcomponents.base=wjcSelf,function(){var t=document.createElement("style");t.innerHTML=`.wj-web-component {\n                display: inline-block;\n            }`,document.head.insertBefore(t,document.head.firstElementChild)}();class WjComponentBehavior{constructor(t){this._isMounted=!1,this._mountedCBs=[],this._isDomInitialized=!1,this._initialValues=[],this.component=t,this.isWrapper||(this.control=t)}static _attach(t){return new this(t)}static register(t,e){if(null==e)return;let o=!!t;if(this._registered.indexOf(e)<0)window.customElements.define(o?t:"wjc-dummy-"+ ++this._cmpRegId,e);else if(o)throw`Wijmo WebComponents error: component '${t}' is already registered.`;if(e.wrappedClass){if(o){let t=this._getMetaData(e).props;for(let o of t){let t=o.propertyName;o.isNativeControlProperty&&(t in HTMLElement.prototype&&console.log(`WARNING: Wijmo WebComponent '${e.name}' exposes the '${t}' property which coinsides with the HTMLElement class member.`),Object.defineProperty(e.prototype,t,{get:function(){return this.control[t]},set:function(e){this.control[t]=e},enumerable:!0,configurable:!0}))}}}else for(let t=Object.getPrototypeOf(e.prototype).constructor;t.prototype!==HTMLElement.prototype&&this._registered.indexOf(t)<0;t=Object.getPrototypeOf(t.prototype).constructor){let e="wjc-dummy-"+ ++this._cmpRegId;this._registered.push(t),window.customElements.define(e,t)}}static getProps(t){return this._ensureMetadata(t),t._props}static ensureNs(t,...e){let o=t.split("."),n=window,i=!0;for(let t of o){let e=n[t];e||(e=n[t]={},i=!1),n=e}if(e)for(let t of e)t&&!n[t]&&(n[t]=null,i=!1);return i}get isWrapper(){return null!=this.component.constructor.wrappedClass}lhConnected(){this.parentComponent=this.component.parentElement,this._prepareControl(),this._isChild()&&this._initParent()}lhDisconnected(){let t=this.control;if(t)if(this._isChild()){let e=this._getParentProp();if(e){let o=this.parentComponent[e];if(wjcCore.isArray(o)){let e=o.indexOf(t);e>-1&&o.splice(e,1)}}}else wjcCore.Control;this.parentComponent=null}lhAttributeChanged(t,e,o){this._onAttributeChanged(t,e,o)}_initParent(){this._callCmpMethod(WjComponentBehavior._beforeInitParent);let t=this._getParentProp();if(t){let e=this.parentComponent.control,o=e[t];if(wjcCore.isArray(o)){let t=this._getSiblingIndex();(t<0||t>=o.length)&&(t=o.length),o.splice(t,0,this.control)}else e[t]=this.control}this._callCmpMethod(WjComponentBehavior._afterInitParent)}_prepareControl(){if(this._isDomInitialized)return;let t=this.component.constructor,e=this.component,o=this.control=t.wrappedClass?this._createControl():e;if(e.control=o,wjcCore.addClass(e,"wj-web-component"),e instanceof wjcCore.Control&&o.hostElement!==e){let t=o.hostElement;t.style.height="100%",t.style.width="100%"}this._isChild()&&(e.style.display="none"),this._initDom(),this._siblingId||(null==t.siblingId&&(t.siblingId=++WjComponentBehavior._siblingDirId+""),this._siblingId=t.siblingId),e.setAttribute(WjComponentBehavior._typeSiblingIdAttr,this._siblingId),this._flushInitialValues(),this._initEvents()}_initDom(){if(this._isDomInitialized)return;this._isDomInitialized=!0;let t=this.control,e=this.component;t instanceof wjcCore.Control&&t.hostElement!==e&&e.appendChild(t.hostElement)}_createControl(){let t=this._isChild()?this._isParentInCtor()?this.parentComponent.control:void 0:this._getElement();return new(WjComponentBehavior._getControlType(this.component.constructor))(t)}_initEvents(){let t=WjComponentBehavior._getMetaData(this.component.constructor);if(t)for(let e of t.events)(t=>{this.control[t.eventName].addHandler((e,o)=>{this.component.dispatchEvent(new CustomEvent(WjComponentBehavior.toDash(t.eventName),{detail:o}))})})(e)}_onAttributeChanged(t,e,o){let n=this.control;if(e!=o)if(n){this._initialValues&&this._flushInitialValues();let e=WjComponentBehavior,i=e._getPropsMetaData(this.component.constructor),r=t,s=e.toCamelCase(t),a=i[r];null!=a&&(o=a.castValueToType(o)),n[s]!==o&&(n[s]=o)}else this._initialValues&&this._initialValues.push({name:t,oldValue:e,newValue:o})}_flushInitialValues(){let t=this._initialValues;if(t){this._initialValues=null;for(let e of t)this._onAttributeChanged(e.name,e.oldValue,e.newValue)}}_isChild(){let t=this.component.constructor;return null!=t.parentProp||null!=t.parentInCtor}_isParentInCtor(){return!0===this.component.constructor.parentInCtor}_getParentProp(){return this.component.getAttribute("wj-property")||this.component.constructor.parentProp}_getSiblingIndex(){var t=this._getElement(),e=t.parentElement;if(!e)return-1;for(var o=e.childNodes,n=-1,i=this._siblingId,r=0;r<o.length;r++){var s=o[r];if(1==s.nodeType&&s.getAttribute(WjComponentBehavior._typeSiblingIdAttr)==i&&(++n,s===t))return n}return-1}_getElement(){return this.component}static _getControlType(t){return t.wrappedClass?t.wrappedClass():Object.getPrototypeOf(t.prototype).constructor}static _getMetaDataId(t){return this._getControlType(t)}static _getMetaData(t){return this._ensureMetadata(t),t._meta}static _getPropsMetaData(t){return this._ensureMetadata(t),t._propsMeta}static _ensureMetadata(t){if(!t._meta){let e=this._getMetaDataId(t);if(e){let o=t._meta=wjcMeta.ControlMetaFactory.getMetaData(e);o.prepare();let n=t._propsMeta={},i=o.props,r=t._props=[];for(let t of i)if(t.propertyType<=wjcMeta.PropertyType.Enum){let e=WjComponentBehavior.toDash(t.propertyName);n[e]=t,r.push(e)}}}}_callCmpMethod(t,...e){let o=this.component,n=o[t];"function"==typeof n&&n.apply(o,e)}static toCamelCase(t){return wjcMeta.ControlMetaFactory.toCamelCase(t)}static toDash(t){return t.replace(/([A-Z])/g,t=>"-"+t[0].toLowerCase())}}WjComponentBehavior._typeSiblingIdAttr="_wjSiblingId",WjComponentBehavior._behClassProp="_wjBehCl",WjComponentBehavior._behProp="_wjBehaviour",WjComponentBehavior._beforeInitParent="_beforeInitParent",WjComponentBehavior._afterInitParent="_afterInitParent",WjComponentBehavior._siblingDirId=0,WjComponentBehavior._cmpRegId=0,WjComponentBehavior._registered=[],exports.WjComponentBehavior=WjComponentBehavior;