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

part of '../task_timeline_card.dart';

/// Private implementation type for `_NoOpIcon` in this library.
/// It keeps supporting state and behavior scoped to the owning file so the public API stays focused on the scheduler concepts that callers use directly.
class _NoOpIcon extends StatelessWidget {
  /// Creates a `_NoOpIcon` 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 _NoOpIcon({
    required this.icon,
    required this.tooltip,
    required this.color,
    required this.metrics,
  });

  /// Stores the `icon` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final IconData icon;

  /// Tooltip message for this inactive icon affordance.
  final String tooltip;

  /// Stores the `color` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Color color;

  /// Stores the `metrics` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final _CardMetrics metrics;

  /// Builds the widget subtree for this component.
  /// The method translates the current widget configuration and state into Flutter UI without mutating scheduler domain data.
  @override
  Widget build(BuildContext context) {
    return Tooltip(
      message: tooltip,
      child: GestureDetector(
        onTap: () {},
        behavior: HitTestBehavior.opaque,
        child: SizedBox.square(
          dimension: metrics.actionButtonSize,
          child: Icon(icon, color: color, size: metrics.actionIconSize),
        ),
      ),
    );
  }
}

/// Private implementation type for `_QuickPushIcon` in this library.
/// It keeps the timeline hover push action visually compact while reusing the same destination menu as the full overdue Push button.
class _QuickPushIcon extends StatelessWidget {
  /// Creates a `_QuickPushIcon` 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 _QuickPushIcon({
    required this.card,
    required this.color,
    required this.metrics,
    required this.isRunning,
    this.onPushToNext,
    this.onPushToTomorrow,
    this.onPushToBacklog,
  });

  /// Stores the `card` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final TimelineCardModel card;

  /// Stores the `color` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Color color;

  /// Stores the `metrics` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final _CardMetrics metrics;

  /// Stores the `isRunning` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final bool isRunning;

  /// Callback invoked when Push to next is selected.
  final Future<void> Function()? onPushToNext;

  /// Callback invoked when Push to tomorrow is selected.
  final Future<void> Function()? onPushToTomorrow;

  /// Callback invoked when Push to backlog is selected.
  final Future<void> Function()? onPushToBacklog;

  /// Builds the widget subtree for this component.
  /// The method translates the current widget configuration and state into Flutter UI without mutating scheduler domain data.
  @override
  Widget build(BuildContext context) {
    final options = _pushDestinationOptions(
      onPushToNext: onPushToNext,
      onPushToTomorrow: onPushToTomorrow,
      onPushToBacklog: onPushToBacklog,
    );
    final enabled = !isRunning && _hasEnabledPushDestination(options);
    return PopupMenuButton<_PastTaskPushDestination>(
      key: ValueKey('${card.id}-quick-push-button'),
      tooltip: 'Push task',
      enabled: enabled,
      color: const Color(0xFF122018),
      elevation: 8,
      position: PopupMenuPosition.under,
      padding: EdgeInsets.zero,
      onSelected: (destination) => _selectPushDestination(destination, options),
      itemBuilder: (context) => _pushDestinationMenuItems(options),
      child: Semantics(
        button: true,
        enabled: enabled,
        label: 'Push ${card.title}',
        child: SizedBox.square(
          dimension: metrics.actionButtonSize,
          child: Icon(
            Icons.arrow_forward,
            color: color,
            size: metrics.actionIconSize,
          ),
        ),
      ),
    );
  }
}
