import 'package:flutter/material.dart';

import 'package:get/get.dart';

import 'package:f0ckapp/controller/settingscontroller.dart';

enum PageTransition { opacity, scale, slide, rotate, flip }

Widget buildAnimatedTransition({
  required BuildContext context,
  required Widget child,
  required PageController pageController,
  required int index,
}) {
  final SettingsController settingsController = Get.find<SettingsController>();
  final double value = pageController.position.haveDimensions
      ? pageController.page! - index
      : 0;

  switch (settingsController.transitionType.value) {
    case PageTransition.opacity:
      return Opacity(
        opacity: Curves.easeOut.transform(1 - value.abs().clamp(0.0, 1.0)),
        child: child,
      );
    case PageTransition.scale:
      return Transform.scale(
        scale:
            0.8 +
            Curves.easeOut.transform(1 - value.abs().clamp(0.0, 1.0)) * 0.2,
        child: child,
      );
    case PageTransition.slide:
      return child;
    case PageTransition.rotate:
      return Opacity(
        opacity: (1 - value.abs()).clamp(0.0, 1.0),
        child: Transform.rotate(angle: value.abs() * 0.5, child: child),
      );
    case PageTransition.flip:
      return Transform(
        transform: Matrix4.identity()
          ..setEntry(3, 2, 0.001)
          ..rotateY(value.abs()),
        alignment: Alignment.center,
        child: child,
      );
  }
}
