import { Component, Inject, Output, EventEmitter } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { ConsultationOrder } from './consultation-order';

@Component({
  selector: 'app-consultation-order-dialog',
  standalone: true,
  imports: [
    CommonModule,
    MatButtonModule,
    MatDialogModule,
    MatIconModule,
    ConsultationOrder
  ],
  templateUrl: './consultation-order-dialog.component.html',
  styleUrls: ['./consultation-order-dialog.component.scss']
})
export class ConsultationOrderDialogComponent {
  @Output() orderCreated = new EventEmitter<any>();

  constructor(
    public dialogRef: MatDialogRef<ConsultationOrderDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any
  ) {}

  onClose(): void {
    this.dialogRef.close();
  }

  // 监听订单分配成功事件
  onOrderCreated(orderData: any): void {
    // 发出订单分配事件
    this.orderCreated.emit(orderData);
    // 关闭弹窗并返回订单数据
    this.dialogRef.close(orderData);
  }
}