"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSubComponentParentId = getSubComponentParentId;
exports.getSubComponentChildren = getSubComponentChildren;
exports.getComponentSubComponentParentId = getComponentSubComponentParentId;
exports.getComponentSubComponentChildren = getComponentSubComponentChildren;
exports.getSpecComponentSpec = getSpecComponentSpec;
exports.getSubComponentSpec = getSubComponentSpec;
exports.getSubComponentChildrenSlot = getSubComponentChildrenSlot;
exports.getSubComponentSlot = getSubComponentSlot;
exports.getSubComponentParentSlotName = getSubComponentParentSlotName;
exports.getSubComponentParentRootIndex = getSubComponentParentRootIndex;
exports.getSpecComponentSpecChildren = getSpecComponentSpecChildren;
exports.getSubComponentRootIndex = getSubComponentRootIndex;
exports.getSubComponentParentIndex = getSubComponentParentIndex;
exports.getDefaultSlotSubComponentId = getDefaultSlotSubComponentId;
function getSubComponentParentId(spec, unitId) {
    return getComponentSubComponentParentId(spec.component ?? {}, unitId);
}
function getSubComponentChildren(spec, unitId) {
    return getComponentSubComponentChildren(spec.component ?? {}, unitId);
}
function getComponentSubComponentParentId(componentSpec, unitId) {
    const { subComponents } = componentSpec;
    for (const subComponentId in subComponents) {
        const subComponent = subComponents[subComponentId];
        const { children = [] } = subComponent;
        for (const childId of children) {
            if (childId === unitId) {
                return subComponentId;
            }
        }
    }
    return null;
}
function getComponentSubComponentChildren(componentSpec, unitId) {
    const { subComponents = {} } = componentSpec;
    const subComponent = subComponents[unitId] ?? {};
    const { children = [] } = subComponent;
    return children;
}
function getSpecComponentSpec(spec) {
    const { component = {} } = spec;
    return component;
}
function getSubComponentSpec(spec, subComponentId) {
    const component = getSpecComponentSpec(spec);
    const { subComponents = {} } = component;
    const subComponent = subComponents[subComponentId];
    return subComponent;
}
function getSubComponentChildrenSlot(spec, subComponentId) {
    const children = getSubComponentChildren(spec, subComponentId);
    const childrenSlotMap = {};
    for (const childId of children) {
        childrenSlotMap[childId] = getSubComponentParentSlotName(spec, childId);
    }
    return childrenSlotMap;
}
function getSubComponentSlot(spec, subComponentId) {
    const component = getSpecComponentSpec(spec);
    const { slots = [] } = component;
    for (const slot of slots) {
        const [slotUnitId, slotName] = slot;
        if (slotUnitId === subComponentId) {
            return slotName;
        }
    }
    return null;
}
function getSubComponentParentSlotName(spec, subComponentId) {
    const parentId = getSubComponentParentId(spec, subComponentId);
    if (parentId) {
        const parentComponentSpec = getSubComponentSpec(spec, parentId);
        const { childSlot = {} } = parentComponentSpec;
        return childSlot[subComponentId] || 'default';
    }
    else {
        return 'default';
    }
}
function getSubComponentParentRootIndex(spec, parentId, unitId) {
    const children = getSubComponentChildren(spec, parentId);
    const index = children.indexOf(unitId);
    return index;
}
function getSpecComponentSpecChildren(spec) {
    const component = getSpecComponentSpec(spec);
    const { children = [] } = component;
    return children;
}
function getSubComponentRootIndex(spec, unitId) {
    const children = getSpecComponentSpecChildren(spec);
    const index = children.indexOf(unitId);
    return index;
}
function getSubComponentParentIndex(spec, unitId) {
    const parentId = getSubComponentParentId(spec, unitId);
    if (parentId) {
        return getSubComponentParentRootIndex(spec, parentId, unitId);
    }
    else {
        return getSubComponentRootIndex(spec, unitId);
    }
}
function getDefaultSlotSubComponentId(spec) {
    const component = getSpecComponentSpec(spec);
    for (const slot of component?.slots ?? []) {
        const [subComponentId, slotName] = slot;
        if (slotName === 'default') {
            return subComponentId;
        }
    }
    return null;
}
//# sourceMappingURL=component.js.map