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

/// Pencil Component/StatusTag — 审批状态标签
class StatusTag extends StatelessWidget {
  final String text;
  final Color? textColor;
  final Color? backgroundColor;
  final double borderRadius;
  final EdgeInsets padding;

  const StatusTag({
    super.key,
    required this.text,
    this.textColor,
    this.backgroundColor,
    this.borderRadius = 4,
    this.padding = const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
  });

  factory StatusTag.fromStatus(String status) {
    final (bg, fg) = _statusProps(status);
    return StatusTag(text: _statusLabel(status), backgroundColor: bg, textColor: fg);
  }

  static String _statusLabel(String s) {
    switch (s) {
      case 'pending':
        return '审批中';
      case 'approved':
        return '已通过';
      case 'rejected':
        return '已拒绝';
      case 'draft':
        return '草稿';
      case 'revoked':
        return '已撤回';
      default:
        return s;
    }
  }

  static (Color, Color) _statusProps(String s) {
    switch (s) {
      case 'pending':
        return (AppColors.warningBg, AppColors.warning);
      case 'approved':
        return (AppColors.successBg, AppColors.success);
      case 'rejected':
        return (AppColors.dangerBg, AppColors.danger);
      case 'draft':
        return (AppColors.bgPage, AppColors.statusGray);
      case 'revoked':
        return (AppColors.revokedBg, AppColors.revokedText);
      default:
        return (AppColors.bgPage, AppColors.statusGray);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: padding,
      decoration: BoxDecoration(
        color: backgroundColor ?? AppColors.successBg,
        borderRadius: BorderRadius.circular(borderRadius),
      ),
      child: Text(
        text,
        style: TextStyle(
          fontSize: 12,
          fontWeight: FontWeight.w500,
          color: textColor ?? AppColors.success,
        ),
      ),
    );
  }
}
