import { LayoutService } from '@/layout/service/layout.service';
import { Component, inject, signal, TemplateRef, ViewChild } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { ConsumerLicenseInfoDialogComponent } from '../components/license-info-dialog.component';
import { CONSUMER_MENU_ITEMS } from '../constants';
import { ConsumerStore } from '../store/main.store';

@Component({
  selector: 'consumer-layout',
  templateUrl: './layout.component.html',
  imports: [RouterOutlet, ConsumerLicenseInfoDialogComponent],
})
export class LayoutComponent {
  @ViewChild('topBarMoreAction') topBarMoreAction!: TemplateRef<any>;

  private readonly layoutService = inject(LayoutService);
  private readonly store = inject(ConsumerStore);

  visibleLicenseInfo = signal(false);

  // licenseStatus = computed(() =>
  //   getLicenseStatus(getLicenseStatus(this.store.entity()?.license_info?.expires_at)),
  // );

  ngOnInit() {
    this.layoutService.setMenuItems(CONSUMER_MENU_ITEMS);
    this.store.getData();
  }

  ngAfterViewInit() {
    this.layoutService.setHeaderSlot(this.topBarMoreAction);
  }

  ngOnDestroy() {
    this.layoutService.setHeaderSlot(null);
  }

  showLicenseInfo() {
    this.visibleLicenseInfo.set(true);
  }
}
