"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSaveContent = void 0;
const getSaveContent = (pageContent, opt) => {
    const { content } = pageContent, pageRest = __rest(pageContent, ["content"]);
    const { schemas = [] } = content, rest = __rest(content, ["schemas"]);
    const { pageNode } = opt;
    let newSchemas = wrapperSchema(schemas);
    // deal with page node
    if (pageNode && pageNode.id) {
        const newPageNode = newSchemas.find((item) => item.id === pageNode.id);
        if (newPageNode) {
            newPageNode.props = pageNode.props;
            newPageNode.directive = pageNode.directive;
        }
        else {
            newSchemas.push(pageNode);
        }
    }
    return Object.assign(Object.assign({}, pageRest), { content: Object.assign(Object.assign({}, rest), { schemas: newSchemas }) });
};
exports.getSaveContent = getSaveContent;
const wrapperSchema = (schemas = []) => {
    const list = [];
    schemas.forEach((item) => {
        const { id, name, label, props, version, type, children = [], extension = {}, directive } = item;
        const node = { id, name, label, props, version, type, extension, directive };
        if (children.length > 0) {
            node.children = wrapperSchema(children);
        }
        list.push(node);
    });
    return list;
};
