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

/// 通话页圆形按钮：Token 色圆底 + 线性图标，禁止位图 PNG。
class LiveButton extends StatelessWidget {
  const LiveButton({
    Key? key,
    required this.icon,
    required this.size,
    required this.background,
    required this.iconColor,
    this.text,
    this.onTap,
  }) : super(key: key);

  final IconData icon;
  final double size;
  final Color background;
  final Color iconColor;
  final String? text;
  final Function()? onTap;

  @override
  Widget build(BuildContext context) {
    final button = Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onTap,
        customBorder: const CircleBorder(),
        child: Ink(
          width: size,
          height: size,
          decoration: BoxDecoration(
            color: background,
            shape: BoxShape.circle,
          ),
          child: Icon(
            icon,
            size: Styles.callIconSize,
            color: iconColor,
          ),
        ),
      ),
    );
    if (text == null || text!.isEmpty) return button;
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        button,
        const SizedBox(height: 8),
        Text(text!, style: Styles.ts_callStatus),
      ],
    );
  }

  static Color get _danger => Styles.c_FF381F;

  static Color get _success => Styles.c_18E875;

  static Color get _white => Styles.c_FFFFFF;

  static Color get _dark => Styles.c_0C1C33;

  LiveButton.mute({
    super.key,
    this.onTap,
    bool muted = false,
  })  : text = StrRes.callMute,
        icon = muted ? Icons.mic_off_outlined : Icons.mic_none_outlined,
        size = Styles.callSecondaryBtn,
        background = muted ? _white : Styles.c_callSecondaryBg,
        iconColor = muted ? _dark : _white;

  LiveButton.handsFree({
    super.key,
    this.onTap,
    bool on = false,
  })  : text = StrRes.callHandsFree,
        icon = Icons.volume_up_outlined,
        size = Styles.callSecondaryBtn,
        background = on ? _white : Styles.c_callSecondaryBg,
        iconColor = on ? _dark : _white;

  LiveButton.hungUp({
    super.key,
    this.onTap,
  })  : text = StrRes.hangUp,
        icon = Icons.call_end,
        size = Styles.callPrimaryBtn,
        background = _danger,
        iconColor = _white;

  LiveButton.reject({
    super.key,
    this.onTap,
  })  : text = StrRes.reject,
        icon = Icons.call_end,
        size = Styles.callPrimaryBtn,
        background = _danger,
        iconColor = _white;

  LiveButton.cancel({
    super.key,
    this.onTap,
  })  : text = StrRes.cancel,
        icon = Icons.call_end,
        size = Styles.callPrimaryBtn,
        background = _danger,
        iconColor = _white;

  LiveButton.pickUp({
    super.key,
    this.onTap,
  })  : text = StrRes.pickUp,
        icon = Icons.phone_outlined,
        size = Styles.callPrimaryBtn,
        background = _success,
        iconColor = _white;
}
