import { Injectable } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { GenericFormComponent, FormConfig } from '../components/generic-form/generic-form.component';
import { Vehicle } from '../../domain/vehicles/vehicle.interface';
import { FinanceSimulatorComponent } from '../../domain/vehicles/finance-simulator.component';
import { SnackNotifyService } from '../components/snack-notify/snack-notify.service';

@Injectable({
  providedIn: 'root'
})
export class DialogService {
  constructor(
    private dialog: MatDialog,
    private snackNotifyService: SnackNotifyService
  ) {}

  openForm(config: FormConfig, initialData?: any) {
    const dialogConfig: MatDialogConfig = {
      width: '90%',
      data: {
        config,
        initialData
      },
      panelClass: 'custom-dialog-container',
      disableClose: true
    };

    return this.dialog.open(GenericFormComponent, dialogConfig);
  }

  openFinanceSimulator(vehicle: Vehicle) {
    return this.dialog.open(FinanceSimulatorComponent, {
      width: '90vw',
      maxWidth: '1200px',
      height: '90vh',
      data: { vehicle }
    });
  }

  openSnackBar(message: string, type: 'success' | 'error' = 'success') {
    console.log('Usando SnackNotify:', { message, type });
    try {
      if (type === 'success') {
        this.snackNotifyService.success(message);
      } else {
        this.snackNotifyService.error(message);
      }
      console.log('SnackNotify exibido com sucesso');
    } catch (error) {
      console.error('Erro ao exibir SnackNotify:', error);
    }
  }
} 