import { BreadcrumbService } from '@/core/services';
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
import { Component, computed, effect, inject, signal } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { PartnerCustomerStore } from '../store/customer.store';

@Component({
  selector: 'partner-customer',
  templateUrl: './single.component.html',
  imports: [AppCardComponent, KeyValueComponent],
})
export class PartnerCustomerComponent {
  private readonly store = inject(PartnerCustomerStore);
  private readonly route = inject(ActivatedRoute);
  private readonly breadcrumbService = inject(BreadcrumbService);

  readonly customerId = signal<string>(this.route.snapshot.paramMap.get('customerId')!);
  editMode = signal<boolean>(false);

  readonly loading = computed(() => this.store.loading());
  readonly customer = computed(() => this.store.entity());
  readonly customerBreadcrumb = computed(() => this.store.breadcrumbItems());

  constructor() {
    effect(() => {
      if (this.customer()?.id) {
        this.setBreadcrumb();
      }
    });
  }

  getData() {
    this.store.getData(this.customerId());
  }

  setBreadcrumb() {
    this.breadcrumbService.setItems(this.customerBreadcrumb());
  }
}
