import * as i0 from '@angular/core';
import { Component, ChangeDetectionStrategy, NgModule } from '@angular/core';
import { isNullOrUndefined } from '@ironsource/fusion-ui/utils';
import { ArcElement, LineElement, BarElement, PointElement, LineController, BarController, PieController, ScatterController, CategoryScale, LinearScale, Filler, Tooltip, Chart } from 'chart.js';
import { ChartBaseComponent, CHART_CONFIGURATIONS, BASE_DATASET_OPTIONS, ChartDataService } from '@ironsource/fusion-ui/components/chart/common/base';
export { ChartDataService, ChartType } from '@ironsource/fusion-ui/components/chart/common/base';
import * as i1 from '@angular/common';
import { DatePipe, CurrencyPipe, DecimalPipe, PercentPipe, CommonModule } from '@angular/common';
import * as i2 from '@ironsource/fusion-ui/components/loader/v1';
import { LoaderModule } from '@ironsource/fusion-ui/components/loader/v1';
import * as i3 from '@ironsource/fusion-ui/pipes/numbers';
import { ShortNumberScaleSuffixPipe } from '@ironsource/fusion-ui/pipes/numbers';
import { ClonePipe } from '@ironsource/fusion-ui/pipes/clone';

function ChartComponent_div_1_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 6);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "shortNumberScaleSuffix");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 1, ctx_r2.pieDataSum));
} }
function ChartComponent_div_1_div_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 7);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(ctx_r3.pieSumLabel);
} }
function ChartComponent_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵtemplate(1, ChartComponent_div_1_div_1_Template, 3, 3, "div", 4)(2, ChartComponent_div_1_div_2_Template, 2, 1, "div", 5);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵclassProp("fu-summary-with-label", ctx_r0.pieSumLabel);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r0.pieDataSum);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r0.pieSumLabel);
} }
function ChartComponent_div_3_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelement(1, "div", 10);
    i0.ɵɵelementStart(2, "div", 11);
    i0.ɵɵtext(3, "No data to display");
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} }
function ChartComponent_div_3_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "fusion-loader", 12);
    i0.ɵɵtext(2, "Loading please wait");
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    i0.ɵɵadvance();
    i0.ɵɵproperty("status", true);
} }
function ChartComponent_div_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 8);
    i0.ɵɵtemplate(1, ChartComponent_div_3_ng_container_1_Template, 4, 0, "ng-container", 9)(2, ChartComponent_div_3_ng_container_2_Template, 3, 1, "ng-container", 9);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵclassProp("fu-loading", ctx_r1.loading);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.noData && !ctx_r1.loading);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r1.loading);
} }
Chart.register(ArcElement, LineElement, BarElement, PointElement, LineController, BarController, PieController, ScatterController, CategoryScale, LinearScale, Filler, Tooltip);
class ChartComponent extends ChartBaseComponent {
    getColors() {
        const palette = this.colorsService.getColorPalette(1);
        const legends = this._data.legends;
        const customPalette = legends
            ? legends.map((legend, idx) => {
                return !isNullOrUndefined(legend.color)
                    ? legend.color
                    : !isNullOrUndefined(palette[idx])
                        ? palette[idx]
                        : '#' + Math.floor(Math.random() * 16777215).toString(16); // no color - gen random
            })
            : palette;
        return customPalette;
    }
    setLineChartOptions(options) {
        // calculate line-point options (if more than 50 points on char)
        if (Array.isArray(this.chartData.datasets) && this.chartData.datasets.length !== 0 && this.chartData.datasets[0].data.length > 50) {
            options.elements.point.pointRadius = 0;
        }
        else {
            options.elements.point.pointRadius = 2;
        }
        this.calcYAxes(options.scales.y);
        if (this.isStacked) {
            this.chartData.datasets.forEach(dataset => {
                if (dataset.label === 'Sum') {
                    dataset['fill'] = false;
                }
            });
        }
    }
    getChartOptionsByStyleVersion() {
        return this.clonePipe.transform(CHART_CONFIGURATIONS.style_v1);
    }
    getDataSetOptionsByStyleVersion() {
        return {
            ...BASE_DATASET_OPTIONS.style_v1
        };
    }
    static { this.ɵfac = /*@__PURE__*/ (() => { let ɵChartComponent_BaseFactory; return function ChartComponent_Factory(t) { return (ɵChartComponent_BaseFactory || (ɵChartComponent_BaseFactory = i0.ɵɵgetInheritedFactory(ChartComponent)))(t || ChartComponent); }; })(); }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ChartComponent, selectors: [["fusion-chart"]], features: [i0.ɵɵInheritDefinitionFeature], decls: 4, vars: 4, consts: [[1, "canvas-holder", 3, "ngClass", "hidden"], ["class", "summary-holder", 3, "fu-summary-with-label", 4, "ngIf"], ["class", "chart-nodata", 3, "fu-loading", 4, "ngIf"], [1, "summary-holder"], ["class", "fu-summary-data", 4, "ngIf"], ["class", "fu-summary-label truncate", 4, "ngIf"], [1, "fu-summary-data"], [1, "fu-summary-label", "truncate"], [1, "chart-nodata"], [4, "ngIf"], [1, "no-data-img"], [1, "no-data-text"], [3, "status"]], template: function ChartComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵtemplate(1, ChartComponent_div_1_Template, 3, 4, "div", 1);
            i0.ɵɵelement(2, "canvas");
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(3, ChartComponent_div_3_Template, 3, 4, "div", 2);
        } if (rf & 2) {
            i0.ɵɵproperty("ngClass", "fu-type-" + ctx.type)("hidden", ctx.loading || ctx.noData);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", ctx.pieDataSum || ctx.pieSumLabel);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngIf", ctx.noData || ctx.loading);
        } }, dependencies: [i1.NgClass, i1.NgIf, i2.LoaderComponent, i3.ShortNumberScaleSuffixPipe], styles: ["[_nghost-%COMP%]   .canvas-holder[_ngcontent-%COMP%]{height:var(--chart-canvas-height, 100%);position:relative}[_nghost-%COMP%]   .canvas-holder[_ngcontent-%COMP%]   canvas[_ngcontent-%COMP%]{position:absolute}[_nghost-%COMP%]   .canvas-holder[_ngcontent-%COMP%]   .summary-holder[_ngcontent-%COMP%]{position:absolute;display:block;text-align:center;top:45%;width:100%}[_nghost-%COMP%]   .canvas-holder[_ngcontent-%COMP%]   .summary-holder.fu-summary-with-label[_ngcontent-%COMP%]{top:38%}[_nghost-%COMP%]   .chart-nodata[_ngcontent-%COMP%]{text-align:center;height:var(--chart-canvas-height, 100%);padding-top:148px}[_nghost-%COMP%]   .chart-nodata[_ngcontent-%COMP%]   .no-data-img[_ngcontent-%COMP%]{display:none}", "[_nghost-%COMP%]   .chart-nodata[_ngcontent-%COMP%]{font-size:18px;font-family:var(--bold-font-family, \"NHaasGroteskTXPro-75Bd\");font-weight:600}[_nghost-%COMP%]   .canvas-holder[_ngcontent-%COMP%]   .summary-holder[_ngcontent-%COMP%]   .fu-summary-data[_ngcontent-%COMP%]{font-size:15px;font-family:var(--bold-font-family, \"NHaasGroteskTXPro-75Bd\");font-weight:600}[_nghost-%COMP%]   .canvas-holder[_ngcontent-%COMP%]   .summary-holder[_ngcontent-%COMP%]   .fu-summary-label[_ngcontent-%COMP%]{font-size:11px;font-family:var(--body-font-family, \"HelveticaNeue\");font-weight:700}[_nghost-%COMP%]   .canvas-holder[_ngcontent-%COMP%]   .summary-holder[_ngcontent-%COMP%]{color:var(--dark-color-300, #172D4C)}[_nghost-%COMP%]   .canvas-holder[_ngcontent-%COMP%]   .summary-holder[_ngcontent-%COMP%]   .fu-summary-label[_ngcontent-%COMP%]{line-height:1}[_nghost-%COMP%]   .chart-nodata[_ngcontent-%COMP%]{color:var(--light-color-700, #95A6B8);border-bottom:solid 1px var(--light-color, #E1E6EB)}"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ChartComponent, [{
        type: Component,
        args: [{ selector: 'fusion-chart', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"canvas-holder\" [ngClass]=\"'fu-type-' + type\" [hidden]=\"loading || noData\">\n    <div class=\"summary-holder\" [class.fu-summary-with-label]=\"pieSumLabel\" *ngIf=\"pieDataSum || pieSumLabel\">\n        <div class=\"fu-summary-data\" *ngIf=\"pieDataSum\">{{pieDataSum | shortNumberScaleSuffix}}</div>\n        <div class=\"fu-summary-label truncate\" *ngIf=\"pieSumLabel\">{{pieSumLabel}}</div>\n    </div>\n    <canvas></canvas>\n</div>\n<div *ngIf=\"noData || loading\" class=\"chart-nodata\" [class.fu-loading]=\"loading\">\n    <ng-container *ngIf=\"noData && !loading\">\n        <div class=\"no-data-img\"></div>\n        <div class=\"no-data-text\">No data to display</div>\n    </ng-container>\n    <ng-container *ngIf=\"loading\">\n        <fusion-loader [status]=\"true\">Loading please wait</fusion-loader>\n    </ng-container>\n</div>\n", styles: [":host .canvas-holder{height:var(--chart-canvas-height, 100%);position:relative}:host .canvas-holder canvas{position:absolute}:host .canvas-holder .summary-holder{position:absolute;display:block;text-align:center;top:45%;width:100%}:host .canvas-holder .summary-holder.fu-summary-with-label{top:38%}:host .chart-nodata{text-align:center;height:var(--chart-canvas-height, 100%);padding-top:148px}:host .chart-nodata .no-data-img{display:none}\n", ":host .chart-nodata{font-size:18px;font-family:var(--bold-font-family, \"NHaasGroteskTXPro-75Bd\");font-weight:600}:host .canvas-holder .summary-holder .fu-summary-data{font-size:15px;font-family:var(--bold-font-family, \"NHaasGroteskTXPro-75Bd\");font-weight:600}:host .canvas-holder .summary-holder .fu-summary-label{font-size:11px;font-family:var(--body-font-family, \"HelveticaNeue\");font-weight:700}:host .canvas-holder .summary-holder{color:var(--dark-color-300, #172D4C)}:host .canvas-holder .summary-holder .fu-summary-label{line-height:1}:host .chart-nodata{color:var(--light-color-700, #95A6B8);border-bottom:solid 1px var(--light-color, #E1E6EB)}\n"] }]
    }], null, null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ChartComponent, { className: "ChartComponent", filePath: "chart.component.ts", lineNumber: 42 }); })();

class ChartModule {
    static { this.ɵfac = function ChartModule_Factory(t) { return new (t || ChartModule)(); }; }
    static { this.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: ChartModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ providers: [DatePipe, CurrencyPipe, DecimalPipe, PercentPipe, ChartDataService, ShortNumberScaleSuffixPipe], imports: [CommonModule, LoaderModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ChartModule, [{
        type: NgModule,
        args: [{
                imports: [CommonModule, LoaderModule, ShortNumberScaleSuffixPipe, ClonePipe],
                declarations: [ChartComponent],
                exports: [ChartComponent],
                providers: [DatePipe, CurrencyPipe, DecimalPipe, PercentPipe, ChartDataService, ShortNumberScaleSuffixPipe]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(ChartModule, { declarations: [ChartComponent], imports: [CommonModule, LoaderModule, ShortNumberScaleSuffixPipe, ClonePipe], exports: [ChartComponent] }); })();

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

export { ChartComponent, ChartModule };
//# sourceMappingURL=ironsource-fusion-ui-components-chart-v1.mjs.map
