import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sigap/src/features/auth/presentasion/controllers/signup/step/identity-verification/identity_verification_controller.dart';
import 'package:sigap/src/shared/widgets/buttons/custom_elevated_button.dart';
import 'package:sigap/src/utils/constants/sizes.dart';

class VerificationActionButton extends StatelessWidget {
  final IdentityVerificationController controller;

  const VerificationActionButton({super.key, required this.controller});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        // Verify data button
        Obx(() {
          if (controller.isVerifying.value) {
            return const Center(child: CircularProgressIndicator());
          }

          return CustomElevatedButton(
            text: 'Verify Information',
            onPressed: () => controller.verifyIdCardWithOCR(),
            icon: Icons.check_circle_outline,
          );
        }),

        const SizedBox(height: TSizes.spaceBtwItems),

        // Save data button - only show when verification is complete
        Obx(() {
          if (!controller.isVerified.value) return const SizedBox.shrink();

          if (controller.isSavingData.value) {
            return Column(
              children: [
                const Center(child: CircularProgressIndicator()),
                const SizedBox(height: TSizes.sm),
                Text(
                  controller.dataSaveMessage.value,
                  textAlign: TextAlign.center,
                  style: Theme.of(context).textTheme.bodySmall,
                ),
              ],
            );
          }

          return Column(
            children: [
              if (controller.isDataSaved.value)
                Container(
                  margin: const EdgeInsets.only(bottom: TSizes.sm),
                  padding: const EdgeInsets.all(TSizes.sm),
                  decoration: BoxDecoration(
                    color: Colors.green.withOpacity(0.1),
                    borderRadius: BorderRadius.circular(TSizes.borderRadiusSm),
                  ),
                  child: Row(
                    children: [
                      Icon(
                        Icons.check_circle,
                        color: Colors.green,
                        size: TSizes.iconSm,
                      ),
                      const SizedBox(width: TSizes.xs),
                      Expanded(
                        child: Text(
                          controller.dataSaveMessage.value,
                          style: Theme.of(
                            context,
                          ).textTheme.bodySmall?.copyWith(color: Colors.green),
                        ),
                      ),
                    ],
                  ),
                ),

              if (!controller.isDataSaved.value)
                CustomElevatedButton(
                  text: 'Save Registration Data',
                  onPressed: () => controller.saveRegistrationData(),
                  icon: Icons.save_outlined,
                ),
            ],
          );
        }),
      ],
    );
  }
}
