import { Component, OnInit, Input } from '@angular/core';
import { DomainPrinterService } from '@domain/printer';
import { PrintModalComponent, PrintModalData } from '@modal/printer';
import { DisplayInfoDTO } from '@generated/swagger/eis-api';
import { UiModalService } from '@ui/modal';
import { TaskCalendarStore } from '../../task-calendar.store';

@Component({
  selector: 'page-task-list-group',
  templateUrl: 'task-list-group.component.html',
  styleUrls: ['task-list-group.component.scss'],
  standalone: false,
})
export class TaskListGroupComponent implements OnInit {
  @Input()
  header: string;

  @Input()
  showPrint: boolean = true;

  @Input()
  showDate: boolean = true;

  @Input()
  items: DisplayInfoDTO[];

  constructor(
    private _modal: UiModalService,
    private _print: DomainPrinterService,
    private _store: TaskCalendarStore,
  ) {}

  ngOnInit() {}

  print(): void {
    this._modal.open({
      content: PrintModalComponent,
      data: {
        printerType: 'Office',
        print: (printer) =>
          this._print
            .printDisplayInfoDTOList({
              displayInfos: this.items,
              printer,
              title: `Tätigkeitskalender \n Liste: ${this.header}`,
            })
            .toPromise(),
      } as PrintModalData,
      config: {
        panelClass: [],
        showScrollbarY: false,
      },
    });
  }

  open(item: DisplayInfoDTO) {
    this._store.open(item);
  }
}
