/**
 * Reusable Resend OTP Component
 * Only visible when resend is allowed (timer expired)
 */

interface ResendOTPProps {
  timer: number;
  onResend: () => void;
  loading?: boolean;
}

function formatTimer(seconds: number): string {
  const mins = Math.floor(seconds / 60);
  const secs = seconds % 60;
  return `${mins}:${secs.toString().padStart(2, "0")}`;
}

export default function ResendOTP({ timer, onResend, loading }: ResendOTPProps) {
  return (
    <div className="col-12 mt-2 text-end">
      {timer > 0 ? (
        <span className="text-sm text-muted">
          Resend OTP in {formatTimer(timer)}
        </span>
      ) : (
        <button
          type="button"
          className="text-sm color-text-first fw-500 cursor-pointer bg-transparent border-0 p-0"
          onClick={onResend}
          disabled={loading}
        >
          {loading ? "Sending..." : "Resend OTP"}
        </button>
      )}

    </div>
  );
}

