"use client";

import type { ReactNode } from "react";
import Link from "next/link";
import { buildCallCopilotHref, openCallCopilotPopup, type CallCopilotLaunchContext } from "@/components/cori/call-copilot-support";

export function CallCopilotLink({ context, className, children }: { context: CallCopilotLaunchContext; className?: string; children: ReactNode }) {
  const href = buildCallCopilotHref(context);
  return (
    <Link
      href={href}
      onClick={(event) => {
        if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) return;
        event.preventDefault();
        openCallCopilotPopup(context);
      }}
      className={className}
    >
      {children}
    </Link>
  );
}
