import { BreadcrumbService } from '@/core/services';
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
import pageParamsUtils from '@/utils/page-params.utils';
import { Component, computed, effect, inject, signal } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { ConsumerBusinessActivitiesFormComponent } from '../../components/businessActivities/form.component';
import { ConsumerComplexesComponent } from '../../components/complexes/list.component';
import { BusinessActivityStore } from '../../store/businessActivity.store';
import { ConsumerStore } from '../../store/consumer.store';

@Component({
  selector: 'superAdmin-user-businessActivity',
  templateUrl: './single.component.html',
  imports: [
    AppCardComponent,
    KeyValueComponent,
    ConsumerBusinessActivitiesFormComponent,
    ConsumerComplexesComponent,
  ],
})
export class SuperAdminUserBusinessActivityComponent {
  private readonly route = inject(ActivatedRoute);
  private readonly breadcrumbService = inject(BreadcrumbService);
  private readonly store = inject(BusinessActivityStore);
  private readonly consumerStore = inject(ConsumerStore);

  pageParams = computed(() => pageParamsUtils(this.route));

  readonly consumerId = signal<string>(this.pageParams()['consumerId']!);
  readonly businessId = signal<string>(this.pageParams()['businessActivityId']!);
  editMode = signal<boolean>(false);

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

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

  getData() {
    this.store.getData(this.consumerId(), this.businessId());
  }

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