import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:loader_overlay/loader_overlay.dart';

import '../../res/app_colors.dart';
import '../constants/app_assets.dart';


class CustomLoading extends StatefulWidget {
  const CustomLoading({Key? key, this.type = 0}) : super(key: key);

  final int type;

  @override
  _CustomLoadingState createState() => _CustomLoadingState();
}

class _CustomLoadingState extends State<CustomLoading> with TickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    _controller = AnimationController(
      duration: const Duration(milliseconds: 800),
      vsync: this,
    );
    _controller.forward();
    _controller.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        _controller.reset();
        _controller.forward();
      }
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Visibility(visible: widget.type == 2, child: _buildLoadingTwo());
  }

  // Widget _buildLoadingOne() {
  //   return Stack(alignment: Alignment.center, children: [
  //     RotationTransition(
  //       alignment: Alignment.center,
  //       turns: _controller,
  //       child: Image.network(
  //         'https://cdn.jsdelivr.net/gh/xdd666t/MyData@master/pic/flutter/blog/20211101174606.png',
  //         height: 110,
  //         width: 110,
  //       ),
  //     ),
  //     Image.network(
  //       'https://cdn.jsdelivr.net/gh/xdd666t/MyData@master/pic/flutter/blog/20211101181404.png',
  //       height: 60,
  //       width: 60,
  //     ),
  //   ]);
  // }

  Widget _buildLoadingTwo() {
    return Container(
      padding: const EdgeInsets.all(30.0),
      decoration: BoxDecoration(
        color: AppColors.white,
        border: Border.all(color: Colors.white),
        borderRadius: BorderRadius.circular(20.0),
      ),
      child: RotationTransition(
        alignment: Alignment.center,
        turns: _controller,
        child: Image(
          image: const AssetImage(AppAssets.kprogresshud_spinner),
          color: Colors.black.withOpacity(0.5),
          height: 50,
          width: 50,
        ),
      ),
    );
  }

  // Widget _buildLoadingThree() {
  //   return Center(
  //     child: Container(
  //       height: 120,
  //       width: 180,
  //       decoration: BoxDecoration(
  //         color: Colors.white,
  //         borderRadius: BorderRadius.circular(15),
  //       ),
  //       alignment: Alignment.center,
  //       child: Column(mainAxisSize: MainAxisSize.min, children: [
  //         RotationTransition(
  //           alignment: Alignment.center,
  //           turns: _controller,
  //           child: Image.network(
  //             'https://cdn.jsdelivr.net/gh/xdd666t/MyData@master/pic/flutter/blog/20211101163010.png',
  //             height: 50,
  //             width: 50,
  //           ),
  //         ),
  //         Container(
  //           margin: EdgeInsets.only(top: 20),
  //           child: Text(TranslationKeys.makeTranslation(TranslationKeys.textLoading)),
  //         ),
  //       ]),
  //     ),
  //   );
  // }

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

showLoader() {
  // Get.context!.loaderOverlay.show(
  //   widgetBuilder: (progress) => const Center(
  //     child: CustomLoading(
  //       type: 2,
  //     ),
  //   ),
  // );

  Get.context!.loaderOverlay.show(
    widgetBuilder: (progress) => const Center(
      child: Card(
        color: Colors.white,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12))),
        child: Padding(
          padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              // SizedBox(
              //   height: 15,
              // ),
              // const CupertinoActivityIndicator(
              //   radius: 25,
              // ),
              CustomLoading(type: 2),
              //SizedBox(height: 15),
              // Text(
              //   "Loading",
              //   style: Theme.of(Get.context!).textTheme.bodyMedium,
              // ),
              // const SizedBox(
              //   height: 15,
              // ),
            ],
          ),
        ),
      ),
    ),
  );
}

hideLoader() {
  Get.context!.loaderOverlay.hide();
}
