import { Component, OnInit } from '@angular/core';
import { DetailsComponentBase } from '@objects-view/details-component-base';
import { IOrderModel } from '@fleio-api/billing/model/order.model';
import { ConfigService } from '@shared/config/config.service';
import { KeyValue } from '@angular/common';

interface CategoryItem {
  value: any;
  nullable?: boolean;
  boolean?: boolean;
  percent?: boolean;
}

@Component({
  selector: 'app-order-details-overview',
  templateUrl: './order-details-overview.component.html',
  styleUrls: ['./order-details-overview.component.scss']
})
export class OrderDetailsOverviewComponent extends DetailsComponentBase<IOrderModel> implements OnInit {
  fraudCheckResults = {};
  fraudCheckCategoryResults: Map<string, ReadonlyMap<string, CategoryItem>> = new Map();
  categoryOrder = (
    a: KeyValue<string, ReadonlyMap<string, CategoryItem>>,
    b: KeyValue<string, ReadonlyMap<string, CategoryItem>>): number => 0;
  categoryItemOrder = (
    a: KeyValue<string, CategoryItem>,
    b: KeyValue<string, CategoryItem>): number => 0;
  resultsOrder = (a: KeyValue<string, object>, b: KeyValue<string, object>): number => 0;

  constructor(
    public config: ConfigService,
  ) {
    super();
  }

  ngOnInit() {
    super.ngOnInit();
    if (this.object?.fraud_check_result) {
      for (const name of Object.keys(this.object.fraud_check_result)) {
        const value = this.object.fraud_check_result[name];
        if (value && typeof value === 'object') {
          this.fraudCheckCategoryResults.set(name, value);
        } else {
          this.fraudCheckResults[name] = value;
        }
      }
    }
  }
}
