// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

import { CommonModule } from '@angular/common';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';

import { ModalController } from '@ionic/angular';
import { ConfigService } from 'src/app/providers/config.service';
import { OrdersService } from 'src/app/providers/orders.service';

@Component({
  imports: [
   	CommonModule,
    FormsModule,
    TranslateModule,
	  IonicModule,
  ],
  providers: [
        TranslateService,
  ],
  selector: 'app-modal-order-detail',
  templateUrl: './modal-order-detail.component.html',
  styleUrl: './modal-order-detail.component.css',
  standalone: true,
})
export class ModalOrderDetailComponent implements OnInit{

  constructor(
          private translate : TranslateService,
          public activeModal: ModalController,
          private ordersService: OrdersService,
          private configService: ConfigService,
          private router: Router,
          private activatedRoute: ActivatedRoute,
  ){}

  @Input() id: number = 0;
  @Input() section: string = '';
  @Output() CloseModal = new EventEmitter<void>();

  data: any;
  onlineshopImageUrl = '';
  cmp_id = 0;
  prt_id = 0;
  lang = 'it';
  lstStati: any[] = [
    { text: 'Acquisito', value: 0, icon:'checkmark-outline', color: '#A9A9A9' },
    { text: 'Rifiutato', value: 0, icon:'checkmark-outline', color: '#A9A9A9' },
    { text: 'Pagato', value: 0, icon:'checkmark-outline', color: '#A9A9A9' },
    { text: 'Spedito', value: 0, icon:'checkmark-outline', color: '#A9A9A9' },
    { text: 'Consegnato', value: 0, icon:'checkmark-outline', color: '#A9A9A9' },
  ];
  responsiveOptions: any[] = [
    { breakpoint: '1024px', numVisible: 5 },
    { breakpoint: '768px', numVisible: 3 },
    { breakpoint: '560px', numVisible: 1 }
  ];
  private paramsSubscription!: Subscription;
  ngOnInit(): void {
    this.onlineshopImageUrl = this.configService.onlineshopImageUrl;
  }

  ionViewWillEnter() {
    this.dettOrd();
  }


  dettOrd(){
    this.ordersService.orders_dett(this.id, this.section).subscribe(res => {
      this.data = res;
      this.status();

    });
 }

 status(){
 for(let i = 0; i<this.lstStati.length; i++){

    if(this.data.ord_lbl_state == this.lstStati[i].text){
      if(this.lstStati[i].text == 'Rifiutato'){
        this.lstStati[i].color = '#8B0000';
        this.lstStati[i].icon = 'close-outline';
      }else{
      this.lstStati[i].color = '#008000';
      }

    }
 }
  }
 

  stamp(){
    this.ordersService.stampa(this.cmp_id, this.lang, this.id, this.section).subscribe(res => {
      /*this.data = res;
      this.status();*/

    });
  }


  closeModal(): void {
    this.activeModal.dismiss();
		this.CloseModal.emit();
	}
}
