import 'package:flutter/material.dart';

import 'package:pweb/models/state/control_state.dart';
import 'package:pweb/utils/dimensions.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


class SendButton extends StatelessWidget {
  final VoidCallback onPressed;
  final ControlState state;

  const SendButton({
    super.key,
    required this.onPressed,
    this.state = ControlState.enabled,
  });

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

    final isEnabled = state == ControlState.enabled;
    final isLoading = state == ControlState.loading;
    final backgroundColor = isEnabled || isLoading
        ? theme.colorScheme.primary
        : theme.colorScheme.onSurface.withValues(alpha: 0.12);
    final textColor = isEnabled || isLoading
        ? theme.colorScheme.onSecondary
        : theme.colorScheme.onSurface.withValues(alpha: 0.38);

    return Center(
      child: SizedBox(
        width: dimensions.buttonWidth,
        height: dimensions.buttonHeight,
        child: InkWell(
          borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
          onTap: isEnabled ? onPressed : null,
          child: Container(
            decoration: BoxDecoration(
              color: backgroundColor,
              borderRadius: BorderRadius.circular(dimensions.borderRadiusSmall),
            ),
            child: Center(
              child: isLoading
                  ? SizedBox(
                      width: dimensions.iconSizeMedium,
                      height: dimensions.iconSizeMedium,
                      child: CircularProgressIndicator(
                        strokeWidth: 2,
                        valueColor: AlwaysStoppedAnimation<Color>(textColor),
                      ),
                    )
                  : Text(
                      AppLocalizations.of(context)!.send,
                      style: theme.textTheme.bodyLarge?.copyWith(
                        color: textColor,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
            ),
          ),
        ),
      ),
    );
  }
}
