import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/subscription_model.dart';
import '../controllers/detail_screen_controller.dart';
import '../widgets/detail/detail_header_section.dart';
import '../widgets/detail/detail_payment_info_section.dart';
import '../widgets/detail/detail_form_section.dart';
import '../widgets/detail/detail_event_section.dart';
import '../widgets/detail/detail_url_section.dart';
import '../widgets/detail/detail_action_buttons.dart';
// import '../theme/app_colors.dart';
import '../l10n/app_localizations.dart';

/// 구독 상세 정보를 표시하고 편집할 수 있는 화면
class DetailScreen extends StatefulWidget {
  final SubscriptionModel subscription;

  const DetailScreen({
    super.key,
    required this.subscription,
  });

  @override
  State<DetailScreen> createState() => _DetailScreenState();
}

class _DetailScreenState extends State<DetailScreen>
    with SingleTickerProviderStateMixin {
  late DetailScreenController _controller;

  @override
  void initState() {
    super.initState();
    _controller = DetailScreenController(
      context: context,
      subscription: widget.subscription,
    );
    _controller.initialize(vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final baseColor = _controller.getCardColor();

    return ChangeNotifierProvider<DetailScreenController>.value(
      value: _controller,
      child: Scaffold(
        backgroundColor: Theme.of(context).colorScheme.surface,
        body: CustomScrollView(
          controller: _controller.scrollController,
          slivers: [
            // 상단 헤더 섹션
            SliverToBoxAdapter(
              child: DetailHeaderSection(
                subscription: widget.subscription,
                controller: _controller,
                fadeAnimation: _controller.fadeAnimation!,
                slideAnimation: _controller.slideAnimation!,
                rotateAnimation: _controller.rotateAnimation!,
              ),
            ),
            // 본문 콘텐츠
            SliverToBoxAdapter(
              child: Padding(
                padding: const EdgeInsets.all(24),
                child: Column(
                  children: [
                    // 편집 모드 안내
                    Container(
                      padding: const EdgeInsets.symmetric(
                        horizontal: 16,
                        vertical: 12,
                      ),
                      decoration: BoxDecoration(
                        color: Theme.of(context)
                            .colorScheme
                            .surfaceContainerHighest
                            .withValues(alpha: 0.4),
                        borderRadius: BorderRadius.circular(16),
                        border: Border.all(
                          color: Theme.of(context)
                              .colorScheme
                              .outline
                              .withValues(alpha: 0.3),
                          width: 1,
                        ),
                      ),
                      child: Row(
                        children: [
                          Icon(
                            Icons.edit_rounded,
                            color: baseColor,
                            size: 20,
                          ),
                          const SizedBox(width: 8),
                          Text(
                            AppLocalizations.of(context).editMode,
                            style: TextStyle(
                              fontSize: 16,
                              fontWeight: FontWeight.w600,
                              color: baseColor,
                            ),
                          ),
                          const Spacer(),
                          Text(
                            AppLocalizations.of(context)
                                .changesAppliedAfterSave,
                            style: TextStyle(
                              fontSize: 14,
                              color: Theme.of(context).colorScheme.onSurface,
                            ),
                          ),
                        ],
                      ),
                    ),
                    const SizedBox(height: 16),

                    DetailPaymentInfoSection(
                      controller: _controller,
                      fadeAnimation: _controller.fadeAnimation!,
                      slideAnimation: _controller.slideAnimation!,
                    ),
                    const SizedBox(height: 16),

                    // 기본 정보 폼 섹션
                    DetailFormSection(
                      controller: _controller,
                      fadeAnimation: _controller.fadeAnimation!,
                      slideAnimation: _controller.slideAnimation!,
                    ),
                    const SizedBox(height: 16),

                    // 이벤트 가격 섹션
                    DetailEventSection(
                      controller: _controller,
                      fadeAnimation: _controller.fadeAnimation!,
                      slideAnimation: _controller.slideAnimation!,
                    ),
                    const SizedBox(height: 16),

                    // 웹사이트 URL 섹션
                    DetailUrlSection(
                      controller: _controller,
                      fadeAnimation: _controller.fadeAnimation!,
                      slideAnimation: _controller.slideAnimation!,
                    ),
                    const SizedBox(height: 32),

                    // 액션 버튼
                    DetailActionButtons(
                      controller: _controller,
                      fadeAnimation: _controller.fadeAnimation!,
                      slideAnimation: _controller.slideAnimation!,
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
