"use client";

import { Button } from "@/components/ui/button";

export function GoogleButton({
  next,
  admin,
  label = "Continue with Google",
  disabled,
}: {
  next?: string;
  admin?: boolean;
  label?: string;
  disabled?: boolean;
}) {
  const params = new URLSearchParams();
  if (next) params.set("next", next);
  if (admin) params.set("admin", "1");
  const qs = params.toString();
  const href = `/api/auth/google/start${qs ? `?${qs}` : ""}`;

  return (
    <a href={href} className="block w-full">
      <Button
        type="button"
        variant="secondary"
        fullWidth
        disabled={disabled}
        aria-label={label}
      >
        <svg
          aria-hidden="true"
          viewBox="0 0 24 24"
          className="h-4 w-4"
        >
          <path
            fill="#EA4335"
            d="M12 11v3.2h4.5c-.2 1.2-1.4 3.4-4.5 3.4-2.7 0-4.9-2.2-4.9-5s2.2-5 4.9-5c1.5 0 2.6.6 3.2 1.2l2.2-2.1C15.9 5.1 14.1 4.3 12 4.3 7.9 4.3 4.6 7.6 4.6 11.7s3.3 7.4 7.4 7.4c4.3 0 7.1-3 7.1-7.3 0-.5-.1-.9-.1-1.3H12z"
          />
        </svg>
        {label}
      </Button>
    </a>
  );
}
