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 { AccountStore } from '../store/account.store';

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

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

  readonly loading = computed(() => this.store.loading());
  readonly account = computed(() => this.store.entity());
  readonly accountBreadcrumb = computed(() => this.store.breadcrumbItems());

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

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

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