import { saveEditors, checkLastUpdated } from "../../../services/api.js";
import { fetchClearCache, fetchRevalidateAll, } from "../../../services/fetcher.js";
import { fetchRevalidate } from "../../../services/fetcher.js";
import { generateShortcut } from "../../../services/keys.js";
import html from "../../../services/html.js";
import t from "../../../i18n/index.js";
import EdenModal from "../../common/eden-modal.js";
import { snackbar } from "../../common/eden-snackbar.js";
export async function openEditStructureModal() {
    const { default: EditStructureModal } = await import("../../plugin/edit-structure-modal.js");
    new EditStructureModal().init();
}
export function openMainPreview() {
    window.open(window.location.href, "eden • Aperçu", "toolbar=0,location=0,status=0,menubar=0,resizable=1,width=2600,height=1200,left=0,top=0,noopener=1,noreferrer=1");
}
export async function refreshMainSite() {
    await fetchClearCache();
    fetchRevalidateAll();
}
export async function openFileManagerModal() {
    const { default: FileManagerModal } = await import("../../plugin/file-manager-modal.js");
    new FileManagerModal({ uploadOnly: true });
}
export async function duplicatePage(lang, path, ignoreFixedEditors) {
    await saveEditors({ lang, path, ignoreFixedEditors });
    fetchRevalidate(lang, path);
    snackbar(t("snackbars.content-duplicated"), "success");
}
export async function showPageDuplicationModal(onDuplicatePage) {
    const { default: EdenPageDuplicationUi } = await import("../eden-page-duplication-ui.js");
    const duplicationModal = new EdenModal({
        title: t("page.duplicate-page"),
        icon: "copy_page",
        content: new EdenPageDuplicationUi(onDuplicatePage),
        noPadding: true,
    });
    document.body.appendChild(duplicationModal);
}
export async function updateUpdatedByTooltip(context) {
    const pathname = window.location.pathname;
    const { lastUpdated, lastUpdatedBy } = await checkLastUpdated(pathname);
    const formatedUpdated = new Date(lastUpdated).toLocaleString("fr-FR");
    context.infoButton.setAttribute("tooltip", html `${t("page.updated-by")} <b>${lastUpdatedBy}</b>
      <br />
      ${t("page.updated-at")} <b>${formatedUpdated}</b>
      <br />
      <div style="margin-top: 5px">
        ${t("page.view-info")} ${generateShortcut("ctrl", "shift", "I")}
      </div>`);
}
