import { Server, Vector } from "./../../library/Minecraft.js";
import { Tool } from "./base_tool.js";
import { Tools } from "./tool_manager.js";
import { Selection } from "./../modules/selection.js";
class CommandButton extends Tool {
    constructor() {
        super(...arguments);
        this.use = function (self, player, session) {
            if (typeof self.command == "string") {
                Server.command.callCommand(player, self.command);
            }
            else {
                Server.command.callCommand(player, self.command[0], self.command.slice(1));
            }
        };
    }
}
class CutTool extends CommandButton {
    constructor() {
        super(...arguments);
        this.command = "cut";
        this.permission = "worldedit.clipboard.cut";
    }
}
Tools.register(CutTool, "cut", "wedit:cut_button");
class CopyTool extends CommandButton {
    constructor() {
        super(...arguments);
        this.command = "copy";
        this.permission = "worldedit.clipboard.copy";
    }
}
Tools.register(CopyTool, "copy", "wedit:copy_button");
class PasteTool extends CommandButton {
    constructor() {
        super(...arguments);
        this.command = ["paste", "-s"];
        this.permission = "worldedit.clipboard.paste";
        this.use = function (self, player, session) {
            Server.command.callCommand(player, self.command[0], self.command.slice(1));
        };
        this.outlines = new Map();
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        this.tick = previewPaste;
    }
}
Tools.register(PasteTool, "paste", "wedit:paste_button");
class UndoTool extends CommandButton {
    constructor() {
        super(...arguments);
        this.command = "undo";
        this.permission = "worldedit.history.undo";
    }
}
Tools.register(UndoTool, "undo", "wedit:undo_button");
class RedoTool extends CommandButton {
    constructor() {
        super(...arguments);
        this.command = "redo";
        this.permission = "worldedit.history.redo";
    }
}
Tools.register(RedoTool, "redo", "wedit:redo_button");
class RotateCWTool extends Tool {
    constructor() {
        super(...arguments);
        this.permission = "worldedit.region.rotate";
        this.use = function (self, player, session) {
            const args = ["90"];
            if (player.isSneaking)
                args.push("-o");
            Server.command.callCommand(player, "rotate", args);
        };
        this.outlines = new Map();
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        this.tick = previewPaste;
    }
}
Tools.register(RotateCWTool, "rotate_cw", "wedit:rotate_cw_button");
class RotateCCWTool extends Tool {
    constructor() {
        super(...arguments);
        this.permission = "worldedit.region.rotate";
        this.use = function (self, player, session) {
            const args = ["-90"];
            if (player.isSneaking)
                args.push("-o");
            Server.command.callCommand(player, "rotate", args);
        };
        this.outlines = new Map();
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        this.tick = previewPaste;
    }
}
Tools.register(RotateCCWTool, "rotate_ccw", "wedit:rotate_ccw_button");
class FlipTool extends Tool {
    constructor() {
        super(...arguments);
        this.permission = "worldedit.region.flip";
        this.use = function (self, player, session) {
            const args = [];
            if (player.isSneaking)
                args.push("-o");
            Server.command.callCommand(player, "flip", args);
        };
        this.outlines = new Map();
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        this.tick = previewPaste;
    }
}
Tools.register(FlipTool, "flip", "wedit:flip_button");
class SpawnGlassTool extends Tool {
    constructor() {
        super(...arguments);
        this.use = function (self, player) {
            Server.queueCommand("setblock ~~~ glass", player);
        };
    }
}
Tools.register(SpawnGlassTool, "spawn_glass", "wedit:spawn_glass");
class ConfigTool extends Tool {
    constructor() {
        super(...arguments);
        this.use = function (self, player, session) {
            session.enterSettings();
        };
    }
}
Tools.register(ConfigTool, "config", "wedit:config_button");
function* previewPaste(self, player, session) {
    if (!session.clipboard || !session.drawOutlines)
        return;
    if (!self.outlines.has(session)) {
        const selection = new Selection(player);
        self.outlines.set(session, selection);
    }
    const [pasteStart, pasteEnd] = session.clipboard.getBounds(Vector.from(player.location).floor().add(0.5), session.clipboardTransform);
    const selection = self.outlines.get(session);
    selection.set(0, pasteStart);
    selection.set(1, pasteEnd);
    selection.draw();
    yield;
}
