/*
    *
    * 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";var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function r(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();Object.defineProperty(exports,"__esModule",{value:!0});var wjcCore=require("wijmo/wijmo"),wjcSelfRef=require("wijmo/wijmo.react.base"),wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.react=window.wijmo.react||{},window.wijmo.react.base=wjcSelf;var ReactDOM=require("react-dom"),React=require("react"),ComponentBase=function(t){function e(e,i,r){var n=t.call(this,e)||this;n._objPropHash={},n._isMounted=!1,n._mountedCBs=[],n.props=e,n.controlType=i;for(var o=0,s=r&&r.objectProps||[];o<s.length;o++){var a=s[o];n._objPropHash[a]=!0}return n}return __extends(e,t),e.prototype.render=function(){var t={};t[e._propsParent]=this;var i=React.Children.map(this.props.children,function(e){return React.cloneElement(e,t)});return React.createElement("div",this._isChild()?{style:{display:"none"}}:null,i)},e.prototype.componentDidMount=function(){var t=this;if(this._isChild()){var i=this.props[e._propsParent];i&&i._mountedCB(function(){t._setParent(i)})}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 i=this.parent.control[e];if(wjcCore.isArray(i)){var r=i.indexOf(t);r>-1&&i.splice(r,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(),i=this._getElement(),r=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]),i.setAttribute(o._typeSiblingIdProp,this._siblingId);var s={};for(var a in r)if(!this._ignoreProp(a))if(a in t)s[a]=r[a];else switch(a){case"className":wjcCore.addClass(i,r.className);break;case"style":wjcCore.setCss(i,r.style);break;default:null!=i[a]&&(i[a]=r[a])}n?t.initialize(s):this._copy(t,s,!0),this._isMounted=!0;var p=this._mountedCBs;this._mountedCBs=[];for(var l=0,c=p;l<c.length;l++)(0,c[l])();wjcCore.isFunction(r.initialized)&&r.initialized(t)},e.prototype._initParent=function(){var t=this._getParentProp();if(t){var e=this.parent.control,i=e[t];if(wjcCore.isArray(i)){var r=this._getSiblingIndex();(r<0||r>=i.length)&&(r=i.length),i.splice(r,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(),i=t.parentElement;if(!i)return-1;for(var r=i.childNodes,n=-1,o=this._siblingId,s=0;s<r.length;s++){var a=r[s];if(1==a.nodeType&&a.getAttribute(e._typeSiblingIdProp)==o&&(++n,a===t))return n}return-1},e.prototype._siblingInserted=function(t){if(t.target===this._getElement()){var e=this._getSiblingIndex(),i=this.control,r=this.parent.control[this._getParentProp()],n=r.indexOf(i);e>=0&&n>=0&&e!==n&&(r.splice(n,1),e=Math.min(e,r.length),r.splice(e,0,i))}},e.prototype._copy=function(t,e,i){if(void 0===i&&(i=!1),t&&e){var r,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))i&&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===(r||(r=this.control)))t[o]=s;else if(wjcCore.isArray(s)&&wjcCore.isArray(t[o])){var a=t[o],p=s;if(p.length==a.length)for(var l=0;l<p.length;l++)this._copy(a[l],p[l])}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 i=t&&t[e];return null!=i&&i 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;