import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';

/// A header widget for sections in the one-time order form.
class OneTimeOrderSectionHeader extends StatelessWidget {
  /// Creates a [OneTimeOrderSectionHeader].
  const OneTimeOrderSectionHeader({
    required this.title,
    this.actionLabel,
    this.onAction,
    super.key,
  });

  /// The title text for the section.
  final String title;

  /// Optional label for an action button on the right.
  final String? actionLabel;

  /// Callback when the action button is tapped.
  final VoidCallback? onAction;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: <Widget>[
        Text(title, style: UiTypography.headline4m.textPrimary),
        if (actionLabel != null && onAction != null)
          TextButton(
            onPressed: onAction,
            style: TextButton.styleFrom(
              padding: EdgeInsets.zero,
              minimumSize: Size.zero,
              tapTargetSize: MaterialTapTargetSize.shrinkWrap,
            ),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                const Icon(UiIcons.add, size: 16, color: UiColors.primary),
                const SizedBox(width: UiConstants.space2),
                Text(
                  actionLabel!,
                  style: UiTypography.body2m.primary,
                ),
              ],
            ),
          ),
      ],
    );
  }
}
