"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handlePaste = void 0;
const clipboard_1 = require("../../../utils/clipboard.js");
const CodeBlockSpecs_1 = require("./CodeBlockSpecs/index.js");
const const_1 = require("./const.js");
const handlePaste = (view, e) => {
    if (!e.clipboardData || view.state.selection.$from.parent.type.spec.code)
        return false;
    const code = getCodeData(e.clipboardData);
    if (!code)
        return false;
    let tr = view.state.tr;
    const { schema } = tr.doc.type;
    const codeBlockNode = (0, const_1.codeBlockType)(schema).create({ [CodeBlockSpecs_1.CodeBlockNodeAttr.Lang]: code.mode }, schema.text(code.value));
    tr = tr.replaceSelectionWith(codeBlockNode);
    view.dispatch(tr.scrollIntoView());
    return true;
};
exports.handlePaste = handlePaste;
function getCodeData(data) {
    if (data.getData(clipboard_1.DataTransferType.Text)) {
        let editor = 'unknown';
        let mode;
        if ((0, clipboard_1.isVSCode)(data)) {
            editor = 'vscode';
            mode = (0, clipboard_1.tryParseVSCodeData)(data)?.mode;
        }
        else
            return null;
        return { editor, mode, value: data.getData(clipboard_1.DataTransferType.Text) };
    }
    return null;
}
//# sourceMappingURL=handle-paste.js.map
