import 'package:flutter/material.dart';
import '../../core/theme/app_colors.dart';
import '../../core/theme/app_colors_extension.dart';

/// Pencil Component/ActionBar — 底部操作栏
///
/// 水平排列三个按钮：重置（可选）、存草稿、提交。
/// 所有按钮圆角22，总高度72，padding 16，gap 12，背景bgCard。
class ActionBar extends StatelessWidget {
  final String? leftLabel;
  final String centerLabel;
  final String rightLabel;
  final VoidCallback? onLeftTap;
  final VoidCallback? onCenterTap;
  final VoidCallback? onRightTap;
  final bool showLeft;

  const ActionBar({
    super.key,
    this.leftLabel,
    required this.centerLabel,
    required this.rightLabel,
    this.onLeftTap,
    this.onCenterTap,
    this.onRightTap,
    this.showLeft = true,
  });

  @override
  Widget build(BuildContext context) {
    final colors = Theme.of(context).extension<AppColorsExtension>()!;
    return Container(
      height: 72,
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
      decoration: BoxDecoration(
        color: colors.bgCard,
      ),
      child: Row(
        children: [
          // 左侧重置按钮（可选显示）
          if (showLeft && leftLabel != null) ...[
            Expanded(
              child: _ActionButton(
                label: leftLabel!,
                backgroundColor: colors.bgCard,
                textColor: colors.textSecondary,
                onTap: onLeftTap,
              ),
            ),
            const SizedBox(width: 12),
          ],
          // 中间存草稿按钮
          Expanded(
            child: _ActionButton(
              label: centerLabel,
              backgroundColor: colors.primaryLight,
              textColor: colors.primary,
              onTap: onCenterTap,
            ),
          ),
          const SizedBox(width: 12),
          // 右侧提交按钮
          Expanded(
            child: _ActionButton(
              label: rightLabel,
              backgroundColor: colors.primary,
              textColor: colors.bgCard,
              onTap: onRightTap,
            ),
          ),
        ],
      ),
    );
  }
}

class _ActionButton extends StatelessWidget {
  final String label;
  final Color backgroundColor;
  final Color textColor;
  final VoidCallback? onTap;

  const _ActionButton({
    required this.label,
    required this.backgroundColor,
    required this.textColor,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 40,
      child: Material(
        color: backgroundColor,
        borderRadius: BorderRadius.circular(22),
        child: InkWell(
          onTap: onTap,
          borderRadius: BorderRadius.circular(22),
          child: Center(
            child: Text(
              label,
              style: TextStyle(
                fontSize: AppFontSizes.body,
                fontWeight: FontWeight.w500,
                color: textColor,
              ),
            ),
          ),
        ),
      ),
    );
  }
}
