import { Component, ChangeDetectionStrategy } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { ModalController } from "@ionic/angular";
import { TranslateService } from "@ngx-translate/core";
import { AbstractHistoryChartOverview } from "src/app/shared/components/chart/abstractHistoryChartOverview";
import { NavigationOption } from "src/app/shared/components/footer/subnavigation/footerNavigation";
import { EdgeConfig, Service, ChannelAddress } from "src/app/shared/shared";

@Component({
    templateUrl: "./overview.html",
    changeDetection: ChangeDetectionStrategy.Eager,
    standalone: false,
})
export class CommonProductionHistoryOverviewComponent extends AbstractHistoryChartOverview {
    protected chargerComponents: EdgeConfig.Component[] = [];
    protected productionMeterComponents: EdgeConfig.Component[] = [];
    protected navigationButtons: NavigationOption[] = [];

    constructor(
        public override service: Service,
        protected override route: ActivatedRoute,
        public override modalCtrl: ModalController,
        private router: Router,
        private translate: TranslateService,
    ) {
        super(service, route, modalCtrl);
    }

    protected override getChannelAddresses(): ChannelAddress[] {
        //  Get Chargers
        this.chargerComponents = this.config
            .getComponentsImplementingNature("io.openems.edge.ess.dccharger.api.EssDcCharger")
            .filter((component) => component.isEnabled);

        // Get productionMeters
        this.productionMeterComponents = this.config
            .getComponentsImplementingNature("io.openems.edge.meter.api.ElectricityMeter")
            .filter((component) => component.isEnabled && this.config.isProducer(component));

        this.navigationButtons = [...this.productionMeterComponents, ...this.chargerComponents].map((el) => ({
            id: el.id,
            alias: el.alias,
            callback: () => {
                this.router.navigate(["./" + el.id], { relativeTo: this.route });
            },
        }));
        return [];
    }
}
