import { BreadcrumbService } from '@/core/services';
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
import { Component, computed, inject, signal } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { GuildGoodCategoriesListComponent } from '../components/categories/list.component';
import { GuildFormComponent } from '../components/form.component';
import { GuildGoodsListComponent } from '../components/goods/list.component';
import { GuildStockKeepingUnitsListComponent } from '../components/stockKeepingUnits/list.component';
import { GuildStore } from '../store/guild.store';

@Component({
  selector: 'admin-guild',
  templateUrl: './single.component.html',
  imports: [
    AppCardComponent,
    KeyValueComponent,
    GuildGoodCategoriesListComponent,
    GuildGoodsListComponent,
    GuildStockKeepingUnitsListComponent,
    GuildFormComponent,
  ],
})
export class GuildComponent {
  private readonly store = inject(GuildStore);
  private readonly breadcrumbService = inject(BreadcrumbService);
  private readonly route = inject(ActivatedRoute);

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

  readonly loading = computed(() => this.store.loading());
  readonly guild = computed(() => this.store.entity());

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

  ngOnInit() {
    this.setBreadcrumb();
  }

  setBreadcrumb() {
    this.breadcrumbService.setItems([...this.store.breadcrumbItems()]);
  }
}
