import 'package:flutter/material.dart';

bool isTalkPowerBlocked({
  required int? talkPower,
  required int? neededTalkPower,
  required bool? talkPowerGranted,
}) {
  return talkPower != null &&
      neededTalkPower != null &&
      talkPower < neededTalkPower &&
      talkPowerGranted != true;
}

class TalkPowerWarning extends StatelessWidget {
  const TalkPowerWarning({
    super.key,
    required this.talkPower,
    required this.neededTalkPower,
    required this.talkPowerGranted,
  });

  final int? talkPower;
  final int? neededTalkPower;
  final bool? talkPowerGranted;

  @override
  Widget build(BuildContext context) {
    if (!isTalkPowerBlocked(
      talkPower: talkPower,
      neededTalkPower: neededTalkPower,
      talkPowerGranted: talkPowerGranted,
    )) {
      return const SizedBox.shrink();
    }

    final theme = Theme.of(context);
    return Container(
      padding: const EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: theme.colorScheme.errorContainer,
        borderRadius: BorderRadius.circular(8),
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Icon(Icons.warning_amber, size: 18, color: theme.colorScheme.error),
          const SizedBox(width: 8),
          Expanded(
            child: Text(
              'Insufficient talk power ($talkPower < $neededTalkPower)',
              style: theme.textTheme.bodySmall?.copyWith(
                color: theme.colorScheme.onErrorContainer,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
