import {Dialog} from "../dialog";
import {fetchPost} from "./fetch";
import {isMobile} from "./functions";
// 需独立出来,否则移动端引用的时候会引入 pc 端大量无用代码
export const renameTag = (labelName: string) => {
const dialog = new Dialog({
title: window.siyuan.languages.rename,
content: `
`,
width: isMobile() ? "92vw": "520px",
});
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
});
const inputElement = dialog.element.querySelector("input");
dialog.bindInput(inputElement, () => {
(btnsElement[1] as HTMLButtonElement).click();
});
inputElement.focus();
inputElement.select();
btnsElement[1].addEventListener("click", () => {
fetchPost("/api/tag/renameTag", {oldLabel: labelName, newLabel: inputElement.value});
});
};
export const getWorkspaceName = () => {
return window.siyuan.config.system.workspaceDir.replace(/^.*[\\\/]/, "");
};