import { computed, Injectable, Signal, signal } from '@angular/core';
import { ViewModeService } from './view-mode.service';
import { FilePreviewStateService } from './file-preview-state.service';
import { ViewMode, ViewModes } from '@red/domain';

const ENABLED_MULTISELECT: ViewMode[] = [ViewModes.STANDARD, ViewModes.TEXT_HIGHLIGHTS];

@Injectable()
export class MultiSelectService {
    readonly enabled = computed(() => this._state.isWritable() && ENABLED_MULTISELECT.includes(this._viewModeService.viewMode()));
    readonly active: Signal<boolean>;
    readonly inactive: Signal<boolean>;

    readonly #active = signal(false);

    constructor(protected readonly _viewModeService: ViewModeService, protected readonly _state: FilePreviewStateService) {
        this.active = this.#active.asReadonly();
        this.inactive = computed(() => !this.#active());
    }

    activate() {
        if (this.enabled()) {
            this.#active.set(true);
        }
    }

    deactivate() {
        this.#active.set(false);
    }
}
