import type { FC } from "react";
import { useTranslation } from "@/i18n/provider.js";
import type { ISimpleFlight } from "../../types.js";
import { AIRLINES } from "./airlines.js";
import "./actions.scss";

export interface RegistrationButtonProps {
  flight: ISimpleFlight;
}

export const RegistrationButton: FC<RegistrationButtonProps> = ({ flight }) => {
  const { t } = useTranslation();

  const handleClick = () => {
    const carrier = flight.operatingBy.carrier;
    if (!carrier) return;
    const config = AIRLINES[carrier];
    if (!config?.registrationUrl) return;
    window.open(config.registrationUrl, "_blank", "noopener,noreferrer");
  };

  return (
    <button
      type="button"
      className="flight-action-btn flight-action-btn--blue-light"
      data-testid="registration-button"
      onClick={handleClick}
    >
      {t("SHARED.ONLINE-REGISTRATION")}
    </button>
  );
};
