import 'package:flutter/material.dart';
import '../../controllers/add_subscription_controller.dart';
import '../common/buttons/primary_button.dart';
import '../../l10n/app_localizations.dart';

/// 구독 추가 화면의 저장 버튼
class AddSubscriptionSaveButton extends StatelessWidget {
  final AddSubscriptionController controller;
  final Animation<double> fadeAnimation;
  final Animation<Offset> slideAnimation;
  final Function setState;

  const AddSubscriptionSaveButton({
    super.key,
    required this.controller,
    required this.fadeAnimation,
    required this.slideAnimation,
    required this.setState,
  });

  @override
  Widget build(BuildContext context) {
    return FadeTransition(
      opacity: Tween<double>(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(
          parent: controller.animationController!,
          curve: const Interval(0.6, 1.0, curve: Curves.easeIn),
        ),
      ),
      child: SlideTransition(
        position: Tween<Offset>(
          begin: const Offset(0.0, 0.6),
          end: Offset.zero,
        ).animate(CurvedAnimation(
          parent: controller.animationController!,
          curve: const Interval(0.6, 1.0, curve: Curves.easeOutCubic),
        )),
        child: Padding(
          padding: const EdgeInsets.only(bottom: 80),
          child: PrimaryButton(
            text: AppLocalizations.of(context).addSubscriptionButton,
            icon: Icons.add_circle_outline,
            onPressed: controller.isLoading
                ? null
                : () => controller.saveSubscription(setState: setState),
            isLoading: controller.isLoading,
            backgroundColor: Theme.of(context).colorScheme.primary,
          ),
        ),
      ),
    );
  }
}
