import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ApiService } from '../../services/api.service';
import { FormsModule } from '@angular/forms';

@Component({
  selector: 'app-settings',
  standalone: true,
  imports: [CommonModule, FormsModule],
  templateUrl: './settings.component.html',
  styleUrls: ['./settings.component.scss']
})
export class SettingsComponent implements OnInit {
  confidence = 0.25;
  notification = '';

  constructor(private apiService: ApiService) {}

  ngOnInit(): void {
    this.apiService.getConfidence().subscribe(res => {
      this.confidence = res.current_confidence;
    });
  }

  saveSettings(): void {
    this.apiService.setConfidence(this.confidence).subscribe({
      next: (res) => {
        this.notification = 'Threshold updated successfully!';
        setTimeout(() => this.notification = '', 3000);
      },
      error: (err) => {
        this.notification = 'Failed to update threshold.';
        setTimeout(() => this.notification = '', 3000);
      }
    });
  }
}
