import * as i0 from '@angular/core';
import { ElementRef, Directive, Inject, Input, NgModule } from '@angular/core';
import { registerElement } from '@nativescript/angular';
import { UIChartsView } from '@nativescript/ui-charts';

registerElement('UIChartsView', () => UIChartsView);
// the actual extended class implementing the bugfix
class UIChartsViewDirective {
    //////////////////////////////////////////////////////////////////////////////////////////////////
    constructor(_elementRef) {
        this._uiChartsView = null;
        this._chartViewLoaded = false;
        this.options = null;
        this.langOptions = null;
        this.updateChartContent = false;
        this._uiChartsView = _elementRef.nativeElement;
        this._uiChartsView.on('loaded', this.onChartViewLoaded, this);
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////
    ngOnDestroy() {
        this._uiChartsView.off('loaded', this.onChartViewLoaded, this);
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////
    onChartViewLoaded(args) {
        this.setChartViewOptions();
        this._chartViewLoaded = true;
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////
    ngOnChanges(changes) {
        for (const propName in changes) {
            if (changes.hasOwnProperty(propName)) {
                switch (propName) {
                    case 'options':
                        if (changes.options.currentValue) {
                            this.options = changes.options.currentValue;
                            if (this._chartViewLoaded) {
                                this.setChartViewOptions();
                            }
                        }
                        break;
                    case 'langOptions':
                        if (changes.langOptions.currentValue) {
                            this.langOptions = changes.langOptions.currentValue;
                            if (this._chartViewLoaded) {
                                this._uiChartsView.setLangOptions(this.langOptions);
                            }
                        }
                        break;
                    case 'updateChartContent':
                        if (changes.updateChartContent) {
                            this.updateChartContent = changes.updateChartContent.currentValue === 'true';
                        }
                        break;
                }
            }
        }
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////
    setChartViewOptions() {
        if (this.options !== null && this.options !== undefined) {
            if (!this._uiChartsView._chartInitialized) {
                this._uiChartsView.setOptions(this.options);
            }
            else {
                if (this.updateChartContent) {
                    this._uiChartsView.updateOptions(this.options);
                }
                else {
                    this._uiChartsView.setOptions(this.options);
                }
            }
        }
    }
}
UIChartsViewDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: UIChartsViewDirective, deps: [{ token: ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
UIChartsViewDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.7", type: UIChartsViewDirective, selector: "UIChartsView", inputs: { options: "options", langOptions: "langOptions", updateChartContent: "updateChartContent" }, usesOnChanges: true, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: UIChartsViewDirective, decorators: [{
            type: Directive,
            args: [{
                    // tslint:disable-next-line: directive-selector
                    selector: 'UIChartsView',
                }]
        }], ctorParameters: function () {
        return [{ type: i0.ElementRef, decorators: [{
                        type: Inject,
                        args: [ElementRef]
                    }] }];
    }, propDecorators: { options: [{
                type: Input
            }], langOptions: [{
                type: Input
            }], updateChartContent: [{
                type: Input
            }] } });
class UIChartsViewModule {
}
UIChartsViewModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: UIChartsViewModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
UIChartsViewModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: UIChartsViewModule, declarations: [UIChartsViewDirective], exports: [UIChartsViewDirective] });
UIChartsViewModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: UIChartsViewModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: UIChartsViewModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [UIChartsViewDirective],
                    exports: [UIChartsViewDirective],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { UIChartsViewDirective, UIChartsViewModule };
//# sourceMappingURL=nativescript-ui-charts-angular.mjs.map
