import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { SubmitQuestionInput } from '../../../../../../core/products/models/product-engagement.model';
import { TranslatePipe } from '../../../../../../i18n/translate.pipe';

@Component({
  selector: 'app-question-form',
  standalone: true,
  imports: [FormsModule, TranslatePipe],
  templateUrl: './question-form.component.html',
  styleUrls: ['./question-form.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class QuestionFormComponent {
  @Input() submitting = false;
  @Output() submitQuestion = new EventEmitter<SubmitQuestionInput>();

  text = '';
  anonymous = false;

  onSubmit(): void {
    const payload: SubmitQuestionInput = {
      text: this.text,
      anonymous: this.anonymous
    };

    if (!payload.text.trim()) {
      return;
    }

    this.submitQuestion.emit(payload);
    this.text = '';
    this.anonymous = false;
  }
}
