import { Component, inject } from '@angular/core';
import { ButtonComponent } from '../../../../shared/components/button/button.component';
import { InputComponent } from '../../../../shared/components/input/input.component';
import { PaginatorComponent } from '../../../../shared/components/paginator/paginator.component';
import { ProductCardComponent } from '../../../../shared/components/product-card/product-card.component';
import { StoreSectionComponent } from '../../../../shared/components/store-section/store-section.component';
import { TenantService } from '../../../../core/services/tenant.service';
import { ToastService } from '../../../../core/services/toast.service';

@Component({
  selector: 'app-reutilizables-test-page',
  imports: [ButtonComponent, InputComponent, PaginatorComponent, ProductCardComponent, StoreSectionComponent],
  templateUrl: './reutilizables-test-page.component.html',
  styleUrl: './reutilizables-test-page.component.scss'
})
export class ReutilizablesTestPageComponent {
  private readonly tenantService = inject(TenantService);
  private readonly toastService = inject(ToastService);
  protected readonly tenant = this.tenantService.tenant;
  protected textValue = 'Auriculares';
  protected numberValue = '24';
  protected email = 'usuario@empresa.com';
  protected user = 'Juan Perez';
  protected password = '12345678';
  protected date = '2026-06-24';
  protected amount = '125000';
  protected percent = '12';
  protected period = '2026-06';
  protected editableValue = 'Solo lectura al cargar';
  protected disabledValue = 'No editable';
  protected invalidEmail = 'correo-invalido';
  protected fileName = '';
  protected clearTrigger = 0;
  protected editableDisabled = true;
  protected currentPage = 1;
  protected readonly paginatorTotalPages = 8;

  protected readonly testProducts = [
    {
      title: 'Pantalón recto de scuba negro',
      originalPrice: 95000,
      discount: 20,
      transferPrice: 74800,
      imageUrl: '/images/pantalon-scuba.png'
    },
    {
      title: 'Zapatillas de running azul',
      originalPrice: 120000,
      discount: 15,
      transferPrice: 98000,
      imageUrl: '/images/zapatillas-running.png'
    },
    {
      title: 'Remera básica blanca (Sin Descuento)',
      originalPrice: 32000,
      discount: null,
      transferPrice: 30000,
      imageUrl: null
    }
  ];

  protected onProductBuy(productTitle: string): void {
    console.log(`Comprando: ${productTitle}`);
    alert(`Comprando: ${productTitle}`);
  }

  protected onFileChange(file: File | null): void {
    this.fileName = file?.name ?? '';
  }

  protected clearFile(): void {
    this.fileName = '';
    this.clearTrigger += 1;
  }

  protected triggerToast(type: 'success' | 'danger' | 'info'): void {
    if (type === 'success') {
      this.toastService.success('¡Operación exitosa! El producto se ha guardado correctamente.');
    } else if (type === 'danger') {
      this.toastService.danger('¡Alerta de error! Hubo un problema al procesar la solicitud.');
    } else if (type === 'info') {
      this.toastService.info('Información del sistema: Hay una nueva actualización disponible.');
    }
  }

  protected triggerPersistentToast(type: 'success' | 'danger' | 'info'): void {
    if (type === 'success') {
      this.toastService.success('¡Éxito persistente! Esta alerta no se cerrará sola.', 0);
    } else if (type === 'danger') {
      this.toastService.danger('¡Error persistente! Por favor, atienda este problema y ciérrelo manualmente.', 0);
    } else if (type === 'info') {
      this.toastService.info('Información persistente: Mantendremos este aviso en pantalla.', 0);
    }
  }
}
