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

class SubscriptionScreen extends StatelessWidget {
  const SubscriptionScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFF2E1065),
      body: SafeArea(
        child: Column(
          children: [
            _buildHeader(context),
            Expanded(
              child: SingleChildScrollView(
                padding: const EdgeInsets.all(16),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    _buildCurrentPlan(),
                    const SizedBox(height: 24),
                    _buildSectionTitle('升级方案'),
                    const SizedBox(height: 12),
                    _buildPlanCard(name: '月度会员', price: '¥29/月', features: ['无限互动时长', '优先匹配', '专属剧本'], isRecommended: false),
                    const SizedBox(height: 12),
                    _buildPlanCard(name: '年度会员', price: '¥199/年', features: ['月度会员全部权益', '额外赠送500积分', '新功能优先体验'], isRecommended: true),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildHeader(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(8, 8, 16, 16),
      child: Row(
        children: [
          IconButton(onPressed: () => Navigator.of(context).pop(), icon: Icon(LucideIcons.chevronLeft, color: Colors.white.withOpacity(0.7))),
          const Text('订阅管理', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white)),
        ],
      ),
    );
  }

  Widget _buildCurrentPlan() {
    return Container(
      padding: const EdgeInsets.all(20),
      decoration: BoxDecoration(
        gradient: const LinearGradient(colors: [Color(0xFF7C3AED), Color(0xFF9333EA)]),
        borderRadius: BorderRadius.circular(20),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Icon(LucideIcons.crown, size: 20, color: const Color(0xFFFBBF24)),
              const SizedBox(width: 8),
              const Text('当前订阅', style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, letterSpacing: 1, color: Colors.white70)),
            ],
          ),
          const SizedBox(height: 8),
          const Text('黑金会员 LV.4', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: Colors.white)),
          const SizedBox(height: 8),
          Text('有效期至 2025-12-31', style: TextStyle(fontSize: 12, color: Colors.white.withOpacity(0.7))),
        ],
      ),
    );
  }

  Widget _buildSectionTitle(String title) {
    return Text(title, style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, letterSpacing: 2, color: Colors.white.withOpacity(0.4)));
  }

  Widget _buildPlanCard({required String name, required String price, required List<String> features, required bool isRecommended}) {
    return Container(
      padding: const EdgeInsets.all(20),
      decoration: BoxDecoration(
        color: Colors.white.withOpacity(0.05),
        borderRadius: BorderRadius.circular(20),
        border: Border.all(color: isRecommended ? const Color(0xFFC084FC) : Colors.white.withOpacity(0.1), width: isRecommended ? 2 : 1),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(name, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white)),
              if (isRecommended)
                Container(
                  padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
                  decoration: BoxDecoration(color: const Color(0xFFC084FC), borderRadius: BorderRadius.circular(8)),
                  child: const Text('推荐', style: TextStyle(fontSize: 10, fontWeight: FontWeight.bold, color: Colors.white)),
                ),
            ],
          ),
          const SizedBox(height: 4),
          Text(price, style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, fontFamily: 'monospace', color: Color(0xFFC084FC))),
          const SizedBox(height: 12),
          ...features.map((f) => Padding(
            padding: const EdgeInsets.only(bottom: 6),
            child: Row(
              children: [
                Icon(LucideIcons.check, size: 14, color: const Color(0xFF34D399)),
                const SizedBox(width: 8),
                Text(f, style: TextStyle(fontSize: 13, color: Colors.white.withOpacity(0.7))),
              ],
            ),
          )),
        ],
      ),
    );
  }
}
