import * as tslib_1 from "tslib";
import * as React from 'react';
import { ReactRenderer } from "igniteui-react-core/ES5/react-renderer";
import { TypeRegistrar } from "igniteui-react-core/ES5/type";
import { IgrPieChartBase } from './igr-pie-chart-base';
import { DataChartStylingDefaults } from './DataChartStylingDefaults';
import { XamPieChart } from './XamPieChart';
var IgrPieChart = /** @class */ (function (_super) {
    tslib_1.__extends(IgrPieChart, _super);
    function IgrPieChart(props) {
        var _this = _super.call(this, props) || this;
        _this._dataSource = null;
        _this._getMainRef = _this._getMainRef.bind(_this);
        var container;
        if (document) {
            container = document.createElement("div");
            container.style.display = "block";
            container.style.width = "100%";
            container.style.height = "100%";
        }
        var root;
        root = container;
        var ren = new ReactRenderer(root, document, true, DataChartStylingDefaults);
        _this.container = ren.getWrapper(container);
        _this._wrapper = ren;
        var chart = _this.i;
        _this._chart = chart;
        chart.provideContainer(ren);
        _this.bindData();
        chart.notifyContainerResized();
        ren.addSizeWatcher(function () {
            _this._chart.notifyContainerResized();
        });
        return _this;
    }
    Object.defineProperty(IgrPieChart.prototype, "height", {
        get: function () {
            return this._height;
        },
        set: function (value) {
            this._height = value;
            if (this._elRef) {
                this._elRef.style.height = value;
                this._chart.notifyContainerResized();
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(IgrPieChart.prototype, "width", {
        get: function () {
            return this._width;
        },
        set: function (value) {
            this._width = value;
            if (this._elRef) {
                this._elRef.style.width = value;
                this._chart.notifyContainerResized();
            }
        },
        enumerable: true,
        configurable: true
    });
    IgrPieChart.prototype._getMainRef = function (ref) {
        this._elRef = ref;
    };
    IgrPieChart.prototype.render = function () {
        var div = React.createElement("div", {
            ref: this._getMainRef
        });
        return div;
    };
    IgrPieChart.prototype.destroy = function () {
        this._chart.destroy();
        this._wrapper.destroy();
    };
    IgrPieChart.prototype.componentDidMount = function () {
        _super.prototype.componentDidMount.call(this);
        this._elRef.style.width = this._width ? this._width : "";
        this._elRef.style.height = this._height ? this._height : "";
        this._elRef.appendChild(this.container.getNativeElement());
        this._chart.notifyContainerResized();
    };
    IgrPieChart.prototype.componentWillUnmount = function () {
        this.destroy();
    };
    IgrPieChart.prototype.createImplementation = function () {
        return new XamPieChart();
    };
    Object.defineProperty(IgrPieChart.prototype, "i", {
        get: function () {
            return this._implementation;
        },
        enumerable: true,
        configurable: true
    });
    IgrPieChart.prototype.createSeriesComponent = function (type) {
        if (TypeRegistrar.isRegistered(type)) {
            var s = TypeRegistrar.create(type);
            s.owner = this;
            s._provideRenderer(this._wrapper);
            return s;
        }
        else {
            //we shouldn't get here, hopefully.
            throw Error("series type not loaded: " + type);
        }
    };
    Object.defineProperty(IgrPieChart.prototype, "dataSource", {
        get: function () {
            return this._dataSource;
        },
        set: function (value) {
            this._dataSource = value;
            this.bindData();
        },
        enumerable: true,
        configurable: true
    });
    IgrPieChart.prototype.bindData = function () {
        if (this._chart != null && this._chart !== undefined) {
            this._chart.itemsSource = this._dataSource;
        }
    };
    Object.defineProperty(IgrPieChart.prototype, "legend", {
        /**
         * Gets or sets the legend used for the current chart.
        */
        get: function () {
            if (this.i.legend != null)
                return this.i.legend.externalObject;
        },
        set: function (v) {
            if (v != undefined && v != null)
                this.i.legend = v.i;
        },
        enumerable: true,
        configurable: true
    });
    return IgrPieChart;
}(IgrPieChartBase));
export { IgrPieChart };
