import { Component, OnInit } from '@angular/core';
import { ClientsPanelComponent } from './clients-panel/clients-panel.component';
import { InvoicesPanelComponent } from './invoices-panel/invoices-panel.component';
import { OperatingSystemsPanelComponent } from './operating-systems-panel/operating-systems-panel.component';
import { FlavorsPanelComponent } from './flavors-panel/flavors-panel.component';
import { AppServicesStatusPanelComponent } from './app-services-status-panel/app-services-status-panel.component';
import { InstancesPanelComponent } from './instances-panel/instances-panel.component';
import { HypervisorsPanelComponent } from './hypervisors-panel/hypervisors-panel.component';
import { AuthService } from '@shared/auth/auth.service';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
  widgetComponentByTitle = {};
  widgetConfigByTitle = {};

  constructor(private auth: AuthService) {
    this.widgetComponentByTitle = {
      Clients: ClientsPanelComponent,
      Invoices: InvoicesPanelComponent,
      'App services': AppServicesStatusPanelComponent,
    };
    if (auth.userData?.edition !== 'web') {
      this.widgetComponentByTitle = Object.assign({}, this.widgetComponentByTitle, {
        Hypervisors: HypervisorsPanelComponent,
        Flavors: FlavorsPanelComponent,
        Instances: InstancesPanelComponent,
        'Operating systems': OperatingSystemsPanelComponent,
      });
    }

    this.widgetConfigByTitle = {
      'App services': {
        title: $localize`App services`,
        component: AppServicesStatusPanelComponent,
        cols: 33,
        rows: 25,
        resizeEnabled: false,
        y: 0,
        x: 0,
        hasReload: true,
        addPaddingLeftRight: true,
        feature: 'core',
      },
      Clients: {
        title: $localize`Clients`,
        component: ClientsPanelComponent,
        cols: 33,
        rows: 13,
        y: 0,
        resizeEnabled: false,
        x: 33,
        hasReload: true,
        addPaddingLeftRight: true,
        feature: 'clients&users.clients',
      },
      Invoices: {
        title: $localize`Invoices`,
        component: InvoicesPanelComponent,
        cols: 33,
        rows: 18,
        resizeEnabled: false,
        y: 0,
        x: 66,
        hasReload: true,
        addPaddingLeftRight: true,
        feature: 'billing.invoices',
      },
    };
    if (auth.userData?.edition !== 'web') {
      this.widgetConfigByTitle = {
        Clients: {
          title: $localize`Clients`,
          component: ClientsPanelComponent,
          cols: 33,
          rows: 13,
          y: 30,
          resizeEnabled: false,
          x: 66,
          hasReload: true,
          addPaddingLeftRight: true,
          feature: 'clients&users.clients',
        },
        Invoices: {
          title: $localize`Invoices`,
          component: InvoicesPanelComponent,
          cols: 33,
          rows: 18,
          resizeEnabled: false,
          y: 43,
          x: 66,
          hasReload: true,
          addPaddingLeftRight: true,
          feature: 'billing.invoices',
        },
        'App services': {
          title: $localize`App services`,
          component: AppServicesStatusPanelComponent,
          cols: 33,
          rows: 25,
          resizeEnabled: false,
          y: 0,
          x: 66,
          hasReload: true,
          addPaddingLeftRight: true,
          feature: 'core',
        },
        Hypervisors: {
          title: $localize`Hypervisors`,
          component: HypervisorsPanelComponent,
          cols: 33,
          rows: 27,
          resizeEnabled: false,
          y: 0,
          x: 33,
          hasReload: true,
          addPaddingLeftRight: true,
          feature: 'openstack',
        },
        Flavors: {
          title: $localize`Flavors`,
          component: FlavorsPanelComponent,
          cols: 33,
          rows: 23,
          y: 23,
          resizeEnabled: false,
          x: 0,
          hasReload: true,
          addPaddingLeftRight: true,
          feature: 'openstack.flavors',
        },
        Instances: {
          title: $localize`Instances`,
          component: InstancesPanelComponent,
          cols: 33,
          rows: 24,
          resizeEnabled: false,
          y: 27,
          x: 33,
          hasReload: true,
          addPaddingLeftRight: true,
          feature: 'openstack.instances',
        },
        'Operating systems': {
          title: $localize`Operating systems`,
          component: OperatingSystemsPanelComponent,
          cols: 33,
          rows: 23,
          y: 0,
          resizeEnabled: false,
          x: 0,
          hasReload: true,
          addPaddingLeftRight: true,
          feature: 'openstack',
        },
      };
    }
  }

  ngOnInit() {
  }

}
