import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../../core/theme/halo_tokens.dart';
import '../../../core/theme/widgets/widgets.dart';
import '../../support/widgets/tanya_admin_sheet.dart';

/// Modal shown when OTP delivery / verification is exhausted (rate-limited
/// 429 from `OTP_RATE_LIMIT_PHONE`, `OTP_RATE_LIMIT_IP`, `OTP_COOLDOWN`, or
/// `OTP_ATTEMPTS_EXCEEDED`). Offers a "lanjut tanpa verif" exit into the
/// anonymous flow (preserving any ESP/USP state) and a "hubungi admin" CTA
/// that opens the Tanya Admin sheet.
class OtpBlockedPopup {
  const OtpBlockedPopup._();

  static Future<void> show(BuildContext context) {
    return HaloPopup.show<void>(
      context,
      title: 'Verifikasi nomor lagi penuh',
      body:
          'Sistem lagi nahan permintaan OTP buat keamanan. Kamu bisa lanjut '
          'tanpa verifikasi, atau hubungi admin biar dibantu manual.',
      icon: Container(
        width: 64,
        height: 64,
        decoration: const BoxDecoration(
          color: HaloTokens.brandSofter,
          shape: BoxShape.circle,
        ),
        alignment: Alignment.center,
        child: const Icon(
          Icons.lock_clock_outlined,
          color: HaloTokens.brandDark,
          size: 28,
        ),
      ),
      primary: HaloPopupAction(
        label: 'lanjut tanpa verif',
        onPressed: () {
          // ESP/USP picks live in Riverpod providers (espSelectionProvider,
          // espSkippedProvider) and survive this navigation — no need to pass
          // them as `extra`.
          context.go('/onboarding/anon/method');
        },
      ),
      secondary: HaloPopupAction(
        label: 'hubungi admin',
        onPressed: () {
          // ignore: discarded_futures
          TanyaAdminSheet.show(context);
        },
      ),
    );
  }
}
