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

/// 결제 주기 선택 위젯
/// 월간, 분기별, 반기별, 연간 중 선택할 수 있습니다.
class BillingCycleSelector extends StatelessWidget {
  final String billingCycle;
  final ValueChanged<String> onChanged;
  final Color? baseColor;
  final List<Color>? gradientColors; // deprecated: ignored
  final bool isGlassmorphism; // deprecated: ignored

  const BillingCycleSelector({
    super.key,
    required this.billingCycle,
    required this.onChanged,
    this.baseColor,
    this.gradientColors,
    this.isGlassmorphism = false,
  });

  @override
  Widget build(BuildContext context) {
    final localization = AppLocalizations.of(context);
    // 상세 화면에서는 '매월', 추가 화면에서는 '월간'으로 표시
    final cycles = [
      localization.monthly,
      localization.billingCycleQuarterly,
      localization.billingCycleHalfYearly,
      localization.yearly,
    ];

    return SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      child: Row(
        children: cycles.map((cycle) {
          final isSelected = billingCycle == cycle;
          return Padding(
            padding: const EdgeInsets.only(right: 8),
            child: InkWell(
              onTap: () => onChanged(cycle),
              borderRadius: BorderRadius.circular(12),
              child: Container(
                padding: const EdgeInsets.symmetric(
                  horizontal: 20,
                  vertical: 12,
                ),
                decoration: BoxDecoration(
                  color: _getBackgroundColor(context, isSelected),
                  borderRadius: BorderRadius.circular(12),
                  border: _getBorder(context, isSelected),
                ),
                child: Text(
                  cycle,
                  style: TextStyle(
                    fontSize: 14,
                    fontWeight: FontWeight.w500,
                    color: _getTextColor(context, isSelected),
                  ),
                ),
              ),
            ),
          );
        }).toList(),
      ),
    );
  }

  Color _getBackgroundColor(BuildContext context, bool isSelected) {
    final scheme = Theme.of(context).colorScheme;
    if (isSelected) {
      return baseColor ?? scheme.primary;
    }
    return scheme.surface;
  }

  Border? _getBorder(BuildContext context, bool isSelected) {
    final scheme = Theme.of(context).colorScheme;
    if (isSelected) return null;
    return Border.all(color: scheme.outline.withValues(alpha: 0.6), width: 1);
  }

  Color _getTextColor(BuildContext context, bool isSelected) {
    final scheme = Theme.of(context).colorScheme;
    return isSelected ? scheme.onPrimary : scheme.onSurface;
  }
}
