import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:taafee_mobile/core/local_storage/local_storage.dart';

import '../../../common/widgets/text.dart';

class OnboardingController extends GetxController {
  PageController pageController = PageController();

  RxList<BoldTextWidget> textList = <BoldTextWidget>[
    const BoldTextWidget(
      'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt 1',
      textAlign: TextAlign.center,
    ),
    const BoldTextWidget(
      'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt 2',
      textAlign: TextAlign.center,
    ),
    const BoldTextWidget(
      'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt 3',
      textAlign: TextAlign.center,
    ),
  ].obs;
  LocalStorage storage = LocalStorage();
  RxList<SvgPicture> picturesList = <SvgPicture>[
    SvgPicture.asset('assets/images/onboarding 1.svg'),
    SvgPicture.asset('assets/images/onboarding 2.svg'),
    SvgPicture.asset('assets/images/onboarding 3.svg'),
  ].obs;
  RxBool isLast = false.obs;
  RxInt currentIndex = 0.obs;
  void changeCurrentIndex(int newIndex) {
    currentIndex.value = newIndex;
    pageController.animateToPage(newIndex,
        duration: const Duration(milliseconds: 200), curve: Curves.easeIn);
    isLast.value = false;
    if (currentIndex.value == 2) {
      isLast.value = true;
    }
    isLast.refresh();
    currentIndex.refresh();
  }

  void increaseIndex() {
    currentIndex.value++;
    pageController.animateToPage(currentIndex.value,
        duration: const Duration(milliseconds: 400), curve: Curves.easeIn);
    if (currentIndex.value == 2) {
      isLast.value = true;
    }
    isLast.refresh();
    currentIndex.refresh();
  }

  void setfirstTimeOpened() async {
    await storage.savefirstTimeOpened();
  }
}
