import 'dart:math';

import 'package:flutter/material.dart';
import 'package:rasadyar_auth/data/di/auth_di.dart';
import 'package:rasadyar_auth/data/models/response/captcha/captcha_response_model.dart';
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
import 'package:rasadyar_core/core.dart';

class CaptchaWidgetLogic extends GetxController with StateMixin<CaptchaResponseModel> {
  Rx<TextEditingController> textController = TextEditingController().obs;
  RxnString captchaKey = RxnString();
  GlobalKey<FormState> formKey = GlobalKey<FormState>();
  AuthRepositoryImpl authRepository = diAuth.get<AuthRepositoryImpl>();
  final Random random = Random();

  @override
  void onInit() {
    super.onInit();

    getCaptcha();
  }

  @override
  void onClose() {
    textController.value.dispose();
    super.onClose();
  }

  Future<void> getCaptcha() async {
    change(null, status: RxStatus.loading());
    textController.value.clear();
    await Future.delayed(Duration(milliseconds: 800));
    captchaKey.value = (random.nextInt(900000)+100000).toString();
    change(value, status: RxStatus.success());

  }
}
