import {Component, computed, inject, input} from '@angular/core';
import {getServerColor, getServerTextColor} from '@pages/altitude/chat/util/server-color';
import {NotificationService} from '@pages/altitude/chat/service/chat-notification.service';
import {NotificationEnabledSvgComponent} from '@pages/altitude/chat/svg/notification-enabled.svg';
import {NotificationDisabledSvgComponent} from '@pages/altitude/chat/svg/notification-disabled.svg';
import {ChatChannel} from '@pages/altitude/chat/objects/chat-channel.object';
import {ColoredNameSegment} from '@pages/altitude/chat/objects/colored-name-segment.object';
import {NameFormatService} from '@pages/altitude/chat/service/name-format.service';

@Component({
  selector: 'app-chat-info',
  imports: [
    NotificationEnabledSvgComponent,
    NotificationDisabledSvgComponent
  ],
  templateUrl: './chat-info.component.html',
  styleUrl: './chat-info.component.scss'
})
export class ChatInfoComponent {
  private readonly notificationService: NotificationService = inject(NotificationService);
  private readonly nameFormatService: NameFormatService = inject(NameFormatService);

  public readonly selectedChannel = input.required<ChatChannel | null>();
  protected readonly channelKey = computed(() => {
    const channel = this.selectedChannel();
    return channel ? `${channel.type}:${channel.name}` : '';
  });
  protected readonly notificationEnabled = computed(() => this.notificationService.isNotificationEnabled(this.channelKey()));
  protected readonly getServerColor = getServerColor;
  protected readonly getServerTextColor = getServerTextColor;

  public enableNotifications() {
    this.notificationService.enableNotifications(this.channelKey());
  }

  public disableNotifications() {
    this.notificationService.disableNotifications(this.channelKey());
  }

  protected getDisplayName(chatChannel: ChatChannel): ColoredNameSegment[] {
    return this.nameFormatService.getDisplayName(chatChannel);
  }

}
