"use client";

import { useTranslations } from "next-intl";
import { FC } from "react";

interface Props {
  className?: string;
  once?: boolean;
  register?: string;
  visit?: string;
  details?: string;
}

function toExternalUrl(url: string) {
  if (!/^https?:\/\//i.test(url)) return `https://${url}`;
  return url;
}

export const EventPageButtons: FC<Props> = ({
  once = false,
  register,
  visit,
  details,
}) => {
  const t = useTranslations("events");

  return (
    <div className="flex items-center gap-6">
      {once ? (
        <>
          <a href={toExternalUrl(register || "")} className="w-full" target="_blank" rel="noopener noreferrer">
            <button className="full-btn bg-PRIMARY py-2.5 text-white">
              {t("registration")}
            </button>
          </a>
          <a href={toExternalUrl(visit || "")} className="w-full" target="_blank" rel="noopener noreferrer">
            <button className="full-btn bg-SECONDARY_CONTAINER py-2.5 text-ON_SECONDARY_CONTAINER">
              {t("visitSite")}
            </button>
          </a>
        </>
      ) : (
        <a href={toExternalUrl(details || "")} className="w-full" target="_blank" rel="noopener noreferrer">
          <button className="full-btn w-full bg-PRIMARY py-2.5 text-white">
            {t("more")}
          </button>
        </a>
      )}
    </div>
  );
};
