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

import 'otp_helper.dart';

class OtpVerificationAdmin extends StatefulWidget {
  final String phone;
  const OtpVerificationAdmin({required this.phone});

  @override
  State<OtpVerificationAdmin> createState() => _OtpVerificationAdminState();
}

class _OtpVerificationAdminState extends State<OtpVerificationAdmin> {
  final _otpController = TextEditingController();
  bool _isLoading = false;

  Future<void> _verifyOtp() async {
    setState(() => _isLoading = true);

    final otpHelper = OtpHelper();
    await otpHelper.verifyOtp(widget.phone, _otpController.text.trim());
    // if (success) {
    //   Get.offAllNamed('/admin-dashboard');
    // } else {
    //   Get.snackbar('خطأ', 'رمز التحقق غير صحيح');
    // }
    setState(() => _isLoading = false);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('التحقق من الرمز')),
      body: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Column(
          children: [
            TextFormField(
              controller: _otpController,
              keyboardType: TextInputType.number,
              decoration: const InputDecoration(labelText: 'رمز التحقق'),
            ),
            const SizedBox(height: 20),
            _isLoading
                ? const CircularProgressIndicator()
                : ElevatedButton(
                    onPressed: _verifyOtp,
                    child: const Text('تحقق وأدخل'),
                  )
          ],
        ),
      ),
    );
  }
}
