import 'package:flutter/material.dart'; import '../../controllers/add_subscription_controller.dart'; import '../common/form_fields/currency_input_field.dart'; import '../common/form_fields/date_picker_field.dart'; /// 구독 추가 화면의 이벤트/할인 섹션 class AddSubscriptionEventSection extends StatelessWidget { final AddSubscriptionController controller; final Animation fadeAnimation; final Animation slideAnimation; final Function setState; const AddSubscriptionEventSection({ super.key, required this.controller, required this.fadeAnimation, required this.slideAnimation, required this.setState, }); @override Widget build(BuildContext context) { return FadeTransition( opacity: Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: controller.animationController!, curve: const Interval(0.4, 1.0, curve: Curves.easeIn), ), ), child: SlideTransition( position: Tween( begin: const Offset(0.0, 0.5), end: Offset.zero, ).animate(CurvedAnimation( parent: controller.animationController!, curve: const Interval(0.4, 1.0, curve: Curves.easeOutCubic), )), child: Container( margin: const EdgeInsets.only(bottom: 20), padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), border: Border.all( color: controller.isEventActive ? const Color(0xFF3B82F6) : Colors.grey.withValues(alpha: 0.2), width: controller.isEventActive ? 2 : 1, ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Checkbox( value: controller.isEventActive, onChanged: (value) { setState(() { controller.isEventActive = value ?? false; if (!controller.isEventActive) { // 이벤트 비활성화 시 관련 데이터 초기화 controller.eventStartDate = DateTime.now(); controller.eventEndDate = DateTime.now().add(const Duration(days: 30)); controller.eventPriceController.clear(); } else { // 이벤트 활성화 시 날짜가 null이면 기본값 설정 controller.eventStartDate ??= DateTime.now(); controller.eventEndDate ??= DateTime.now().add(const Duration(days: 30)); } }); }, activeColor: const Color(0xFF3B82F6), ), const Text( '이벤트/할인 설정', style: TextStyle( fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1E293B), ), ), const SizedBox(width: 8), Icon( Icons.local_offer, size: 20, color: controller.isEventActive ? const Color(0xFF3B82F6) : Colors.grey, ), ], ), // 이벤트 활성화 시 추가 필드 표시 AnimatedContainer( duration: const Duration(milliseconds: 300), height: controller.isEventActive ? null : 0, child: AnimatedOpacity( duration: const Duration(milliseconds: 300), opacity: controller.isEventActive ? 1.0 : 0.0, child: Column( children: [ const SizedBox(height: 20), // 이벤트 기간 DateRangePickerField( startDate: controller.eventStartDate, endDate: controller.eventEndDate, onStartDateSelected: (date) { setState(() { controller.eventStartDate = date; }); }, onEndDateSelected: (date) { setState(() { controller.eventEndDate = date; }); }, startLabel: '시작일', endLabel: '종료일', primaryColor: const Color(0xFF3B82F6), ), const SizedBox(height: 20), // 이벤트 가격 CurrencyInputField( controller: controller.eventPriceController, currency: controller.currency, label: '이벤트 가격', hintText: '할인된 가격을 입력하세요', ), ], ), ), ), ], ), ), ), ); } }