// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

part of '../../timeline_state.dart';

/// Reduced Today timeline state for manual compact mode.
class CompactTimelineState {
  /// Creates a `CompactTimelineState` instance with the values required by its invariants.
  /// Callers should pass already-normalized scheduler data because validation and defaulting belong at the model or service boundary, not in arbitrary UI code.
  const CompactTimelineState({
    required this.manualCompactModeEnabled,
    required this.fullTimelineExpanded,
    this.currentItem,
    this.nextRequiredItem,
    this.nextFlexibleItem,
  });

  /// User-controlled compact mode flag.
  final bool manualCompactModeEnabled;

  /// Whether the full timeline is expanded while compact mode is active.
  final bool fullTimelineExpanded;

  /// Current visible task, if one is active or occupies the query time.
  final TimelineItem? currentItem;

  /// Next critical or inflexible task after the current moment.
  final TimelineItem? nextRequiredItem;

  /// Optional next flexible task after the current moment.
  final TimelineItem? nextFlexibleItem;

  /// Whether callers should show the full timeline.
  bool get fullTimelineVisible {
    return !manualCompactModeEnabled || fullTimelineExpanded;
  }

  /// Items selected for the compact view.
  List<TimelineItem> get compactItems {
    if (!manualCompactModeEnabled) {
      return const [];
    }
    return [
      if (currentItem != null) currentItem!,
      if (nextRequiredItem != null && nextRequiredItem!.id != currentItem?.id)
        nextRequiredItem!,
      if (nextFlexibleItem != null &&
          nextFlexibleItem!.id != currentItem?.id &&
          nextFlexibleItem!.id != nextRequiredItem?.id)
        nextFlexibleItem!,
    ];
  }
}
