// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
import { Maybe } from '@/core';
import { PosInfoStore } from '@/domains/pos/store/pos.store';
import { AbstractIsMobileComponent } from '@/shared/abstractClasses/abstract-is-mobile';
import { SharedDialogComponent } from '@/shared/components';
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
import { PriceMaskDirective } from '@/shared/directives';
import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
import { ButtonDirective } from 'primeng/button';
import { PosGoodsComponent } from '../components/goods.component';
import { PosOrderSectionComponent } from '../components/order/order-section.component';
import { PosOrderSubmittedDialogComponent } from '../components/order/order-submitted-dialog.component';
import { IPosOrderResponse } from '../models';
import { PosLandingStore } from '../store/main.store';

@Component({
  selector: 'pos-landing',
  templateUrl: './root.component.html',
  host: { class: 'grow overflow-hidden' },
  changeDetection: ChangeDetectionStrategy.OnPush,

  imports: [
    PosGoodsComponent,
    PosOrderSectionComponent,
    PageLoadingComponent,
    PriceMaskDirective,
    SharedDialogComponent,
    ButtonDirective,
    PosOrderSubmittedDialogComponent,
  ],
})
export class PosLandingComponent extends AbstractIsMobileComponent {
  private readonly infoStore = inject(PosInfoStore);
  private readonly landingStore = inject(PosLandingStore);

  isVisibleSuccessDialog = signal(false);
  responseInvoice = signal<Maybe<IPosOrderResponse>>(null);

  readonly loading = computed(() => this.infoStore.loading());
  readonly pos = computed(() => this.infoStore.entity());
  readonly error = computed(() => this.infoStore.error());
  readonly inOrderGoods = computed(() => this.landingStore.inOrderGoods());
  readonly priceInfo = computed(() => this.landingStore.orderPricingInfo());
  readonly showInvoiceBottomSheet = signal(false);

  // getData() {
  //   this.infoStore.getData().subscribe();
  // }

  openInvoiceBottomSheet() {
    this.showInvoiceBottomSheet.set(true);
  }

  closeInvoiceBottomSheet() {
    this.showInvoiceBottomSheet.set(false);
  }

  onSuccessSubmit(invoice: IPosOrderResponse) {
    this.closeInvoiceBottomSheet();
    this.responseInvoice.set(invoice);
    this.isVisibleSuccessDialog.set(true);
  }

  closeSuccessDialog() {
    this.isVisibleSuccessDialog.set(false);
  }
}
