"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImageSpecs = exports.ImageAttr = exports.imageType = exports.imageNodeName = void 0;
const schema_1 = require("../../../../utils/schema.js");
exports.imageNodeName = 'image';
exports.imageType = (0, schema_1.nodeTypeFactory)(exports.imageNodeName);
exports.ImageAttr = {
    Src: 'src',
    Alt: 'alt',
    Title: 'title',
    Loading: 'loading',
};
const ImageSpecs = (builder) => {
    builder.addNode(exports.imageNodeName, () => ({
        spec: {
            inline: true,
            attrs: {
                [exports.ImageAttr.Src]: {},
                [exports.ImageAttr.Alt]: { default: null },
                [exports.ImageAttr.Title]: { default: null },
                [exports.ImageAttr.Loading]: { default: null },
            },
            group: 'inline',
            draggable: true,
            parseDOM: [
                {
                    tag: 'img[src]',
                    getAttrs(dom) {
                        return {
                            [exports.ImageAttr.Src]: dom.getAttribute(exports.ImageAttr.Src),
                            [exports.ImageAttr.Alt]: dom.getAttribute(exports.ImageAttr.Alt),
                            [exports.ImageAttr.Title]: dom.getAttribute(exports.ImageAttr.Title),
                            [exports.ImageAttr.Loading]: dom.getAttribute(exports.ImageAttr.Loading),
                        };
                    },
                },
            ],
            toDOM(node) {
                return ['img', node.attrs];
            },
        },
        fromMd: {
            tokenSpec: {
                name: exports.imageNodeName,
                type: 'node',
                getAttrs: (tok) => ({
                    [exports.ImageAttr.Src]: tok.attrGet('src'),
                    [exports.ImageAttr.Title]: tok.attrGet('title') || null,
                    [exports.ImageAttr.Loading]: tok.attrGet(exports.ImageAttr.Loading) || null,
                    [exports.ImageAttr.Alt]: tok.children?.[0]?.content || null,
                }),
            },
        },
        toMd: (state, { attrs }) => {
            let result = '![';
            if (attrs.alt) {
                result += state.esc(attrs.alt);
            }
            result += '](';
            if (attrs.src) {
                result += state.esc(attrs.src);
            }
            if (attrs.title) {
                result += ` ${state.quote(attrs.title)}`;
            }
            result += ')';
            state.write(result);
        },
    }));
};
exports.ImageSpecs = ImageSpecs;
//# sourceMappingURL=index.js.map
