import { shellApi } from "../../api/api";
import { getPatientCip } from "../get-patient-cip/action";

export const navigateToEcap = async (
  eventName: string,
  closeAction = "NO_TANCAR",
  additionalParams: Record<string, string> = {},
  includeCip = true,
) => {
  const params = { ...additionalParams };

  try {
    if (includeCip) {
      const CIP = await getPatientCip(shellApi);
      params.CIP = CIP;
      shellApi.ecapEventManager.publish(eventName, closeAction, params);
    }
  } catch (error) {
    console.error(error);
  }
};
