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

import '../../../shared/theme/app_theme.dart';

class StepperRow extends StatelessWidget {
  final String title;
  final String display;
  final VoidCallback? onDecrement;
  final VoidCallback? onIncrement;

  const StepperRow({
    super.key,
    required this.title,
    required this.display,
    this.onDecrement,
    this.onIncrement,
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final tokens = context.appTokens;

    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
      child: Row(
        children: [
          Expanded(
            child: Text(
              title,
              style: theme.textTheme.bodyMedium?.copyWith(
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
          _stepBtn(Icons.remove, onDecrement, theme),
          SizedBox(
            width: 52,
            child: Text(
              display,
              textAlign: TextAlign.center,
              style: theme.textTheme.bodyMedium?.copyWith(
                color: tokens.mutedForeground,
              ),
            ),
          ),
          _stepBtn(Icons.add, onIncrement, theme),
        ],
      ),
    );
  }

  Widget _stepBtn(IconData icon, VoidCallback? onPressed, ThemeData theme) {
    return SizedBox.square(
      dimension: 28,
      child: FButton.icon(
        variant: FButtonVariant.ghost,
        size: FButtonSizeVariant.xs,
        onPress: onPressed,
        child: Icon(
          icon,
          size: 14,
          color: onPressed != null
              ? theme.colorScheme.onSurface
              : theme.colorScheme.onSurface.withValues(alpha: 0.25),
        ),
      ),
    );
  }
}
