import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:kasy_kit/core/animations/movefade_anim.dart';
import 'package:kasy_kit/core/theme/theme.dart';

/// Rodapé fixo do onboarding: fundo até a borda inferior + animação de entrada.
class OnboardingStickyFooter extends StatelessWidget {
  const OnboardingStickyFooter({
    super.key,
    required this.children,
    this.animate = true,
    this.animationDelayMs = 400,
    this.horizontalPadding = KasySpacing.lg,
    this.maxContentWidth,
  });

  final List<Widget> children;
  final bool animate;
  final int animationDelayMs;
  final double horizontalPadding;

  /// Largura máxima do conteúdo (ex.: 600 em telas médias).
  final double? maxContentWidth;

  @override
  Widget build(BuildContext context) {
    final bottomInset = MediaQuery.viewPaddingOf(context).bottom;

    Widget content = Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: children,
    );

    if (maxContentWidth != null) {
      content = Center(
        child: ConstrainedBox(
          constraints: BoxConstraints(maxWidth: maxContentWidth!),
          child: content,
        ),
      );
    }

    Widget footer = Container(
      width: double.infinity,
      decoration: BoxDecoration(
        color: context.colors.background,
        boxShadow: [
          BoxShadow(
            color: context.colors.onBackground.withValues(alpha: 0.06),
            blurRadius: 16,
            offset: const Offset(0, -4),
          ),
        ],
      ),
      padding: EdgeInsets.fromLTRB(
        horizontalPadding,
        KasySpacing.md,
        horizontalPadding,
        KasySpacing.md +
            bottomInset +
            (defaultTargetPlatform == TargetPlatform.android
                ? KasySpacing.sm
                : 0),
      ),
      child: content,
    );

    if (animate) {
      footer = MoveFadeAnim(
        delayInMs: animationDelayMs,
        child: footer,
      );
    }

    return footer;
  }
}
