/*
    *
    * Wijmo Library 5.20183.550
    * 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";var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function i(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}}();Object.defineProperty(exports,"__esModule",{value:!0});var wjcCore=require("wijmo/wijmo"),__glob="undefined"!=typeof window?window:self,wjcSelfRef=require("wijmo/wijmo.react.base"),wjcSelf=wjcSelfRef||exports;__glob.wijmo=__glob.wijmo||{},__glob.wijmo.react=__glob.wijmo.react||{},__glob.wijmo.react.base=wjcSelf;var ReactDOM=require("react-dom"),React=require("react"),ComponentBase=function(t){function e(e,r,i){var n=t.call(this,e)||this;n._objPropHash={},n._isMounted=!1,n._mountedCBs=[],n.props=e,n.controlType=r;for(var o=0,s=i&&i.objectProps||[];o<s.length;o++){var l=s[o];n._objPropHash[l]=!0}return n}return __extends(e,t),e.prototype.render=function(){var t={};t[e._propsParent]=this;var r=React.Children.map(this.props.children,function(e){return React.cloneElement(e,t)});return React.createElement("div",this._isChild()?{style:{display:"none"}}:null,r)},e.prototype.componentDidMount=function(){var t=this;if(this._isChild()){var r=this.props[e._propsParent];r&&r._mountedCB(function(){t._setParent(r)})}else this._prepareControl();return this.control},e.prototype.componentWillUnmount=function(){this._siblingInsertedEH&&this._getElement().removeEventListener("DOMNodeInserted",this._siblingInsertedEH);var t=this.control;if(t)if(this._isChild()){var e=this._getParentProp();if(e){var r=this.parent.control[e];if(wjcCore.isArray(r)){var i=r.indexOf(t);i>-1&&r.splice(i,1)}}}else t instanceof wjcCore.Control&&t.dispose()},e.prototype.shouldComponentUpdate=function(t){var e=this.control;return this._copy(e,t),!0},e.prototype._mountedCB=function(t){this._isMounted?t():this._mountedCBs.push(t)},e.prototype._createControl=function(){var t=this._isChild()?this._isParentInCtor()?this.parent.control:void 0:this._getElement();return new this.controlType(t)},e.prototype._prepareControl=function(){var t=this.control=this._createControl(),r=this._getElement(),i=this.props,n=t instanceof wjcCore.Control,o=e;this._siblingId||(null==this.constructor[o._typeSiblingIdProp]&&(this.constructor[o._typeSiblingIdProp]=++o._siblingDirId+""),this._siblingId=this.constructor[o._typeSiblingIdProp]),r.setAttribute(o._typeSiblingIdProp,this._siblingId);var s={};for(var l in i)if(!this._ignoreProp(l))if(l in t)s[l]=i[l];else switch(l){case"className":wjcCore.addClass(r,i.className);break;case"style":wjcCore.setCss(r,i.style);break;default:null!=r[l]&&(r[l]=i[l])}n?t.initialize(s):this._copy(t,s,!0),this._isMounted=!0;var p=this._mountedCBs;this._mountedCBs=[];for(var a=0,c=p;a<c.length;a++)(0,c[a])();wjcCore.isFunction(i.initialized)&&i.initialized(t)},e.prototype._initParent=function(){var t=this._getParentProp();if(t){var e=this.parent.control,r=e[t];if(wjcCore.isArray(r)){var i=this._getSiblingIndex();(i<0||i>=r.length)&&(i=r.length),r.splice(i,0,this.control),this._siblingInsertedEH=this._siblingInserted.bind(this),this._getElement().addEventListener("DOMNodeInserted",this._siblingInsertedEH)}else e[t]=this.control}},e.prototype._setParent=function(t){if(t!==this.parent){if(this.parent)throw"Wijmo child component is already attached to a different parent.";this.parent=t,this._prepareControl(),this._initParent()}},e.prototype._isChild=function(){return null!=this._parentProp||null!=this._parentInCtor},e.prototype._isParentInCtor=function(){return!0===this._parentInCtor},e.prototype._getParentProp=function(){return this.props.wjProperty||this._parentProp},e.prototype._getSiblingIndex=function(){var t=this._getElement(),r=t.parentElement;if(!r)return-1;for(var i=r.childNodes,n=-1,o=this._siblingId,s=0;s<i.length;s++){var l=i[s];if(1==l.nodeType&&l.getAttribute(e._typeSiblingIdProp)==o&&(++n,l===t))return n}return-1},e.prototype._siblingInserted=function(t){if(t.target===this._getElement()){var e=this._getSiblingIndex(),r=this.control,i=this.parent.control[this._getParentProp()],n=i.indexOf(r);e>=0&&n>=0&&e!==n&&(i.splice(n,1),e=Math.min(e,i.length),i.splice(e,0,r))}},e.prototype._copy=function(t,e,r){if(void 0===r&&(r=!1),t&&e){var i,n=t===this.control;for(var o in e)if(!this._ignoreProp(o)||!n){var s=e[o];if(o in t){if(this._isEvent(t,o))r&&wjcCore.isFunction(s)&&t[o].addHandler(s);else if(!this._sameValue(t[o],s))if(null==s)t[o]=s;else if(wjcCore.isPrimitive(s)||wjcCore.isFunction(s)||this._objPropHash[o]&&t===(i||(i=this.control)))t[o]=s;else if(wjcCore.isArray(s)&&wjcCore.isArray(t[o])){var l=t[o],p=s;if(p.length==l.length)for(var a=0;a<p.length;a++)this._copy(l[a],p[a])}else wjcCore.isObject(s)&&this._copy(t[o],e[o])}else"className"==o?t.hostElement&&wjcCore.addClass(t.hostElement,e[o]):"style"==o&&t.hostElement&&wjcCore.setCss(t.hostElement,e[o])}}},e.prototype._sameValue=function(t,e){return t==e||wjcCore.DateTime.equals(t,e)},e.prototype._isEvent=function(t,e){var r=t&&t[e];return null!=r&&r instanceof wjcCore.Event},e.prototype._getElement=function(){return ReactDOM.findDOMNode(this)},e.prototype._ignoreProp=function(t){return"children"===t},e._propsParent="$parent",e._typeSiblingIdProp="_wjSiblingIdProp",e._siblingDirId=0,e}(React.Component);exports.ComponentBase=ComponentBase;