import { l as logger } from "./orgDomains-eTg-cjth.js";
import { a as appStore } from "./index-uMmDQCED.js";
const log = logger.getSubLogger({ prefix: ["CalendarManager"] });
const isCalendarService = (x) => !!x && typeof x === "object" && "lib" in x && typeof x.lib === "object" && !!x.lib && "CalendarService" in x.lib;
const getCalendar = async (credential) => {
  if (!credential || !credential.key)
    return null;
  let { type: calendarType } = credential;
  if (calendarType?.endsWith("_other_calendar")) {
    calendarType = calendarType.split("_other_calendar")[0];
  }
  if (calendarType?.endsWith("_crm")) {
    calendarType = calendarType.split("_crm")[0];
  }
  const calendarAppImportFn = appStore[calendarType.split("_").join("")];
  if (!calendarAppImportFn) {
    log.warn(`calendar of type ${calendarType} is not implemented`);
    return null;
  }
  const calendarApp = await calendarAppImportFn();
  if (!isCalendarService(calendarApp)) {
    log.warn(`calendar of type ${calendarType} is not implemented`);
    return null;
  }
  const CalendarService = calendarApp.lib.CalendarService;
  return new CalendarService(credential);
};
export {
  getCalendar as g
};
