"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.$appendChild = $appendChild;
exports.$removeChild = $removeChild;
exports.$hasChild = $hasChild;
exports.$child = $child;
exports.$children = $children;
exports.$refRoot = $refRoot;
exports.$refChild = $refChild;
exports.$getAnimations = $getAnimations;
exports.$getSetup = $getSetup;
const Async_1 = require("../types/interface/async/Async");
function $appendChild(component, Class, callback) {
    const i = component.appendChild(Class);
    callback(i);
}
function $removeChild(component, { at }, callback) {
    try {
        const child = component.removeChild(at);
        const bundle = child.getUnitBundleSpec();
        const specId = bundle.unit.id;
        callback({ specId });
    }
    catch (err) {
        callback(undefined, err.message);
    }
}
function $hasChild(component, { at }, callback) {
    const has = component.hasChild(at);
    callback(has);
}
function $child(component, { at }, callback) {
    const child = component.refChild(at);
    // @ts-ignore
    const id = child.constructor.id;
    callback(id);
}
function $children(component, {}, callback) {
    const children = component.refChildren();
    const _children = children.map((c) => {
        return { bundle: c.getUnitBundleSpec() };
    });
    callback(_children);
}
function $refRoot(component, { at, _ }) {
    const root = component.refRoot(at);
    const $root = (0, Async_1.Async)(root, _, component.__system.async);
    return $root;
}
function $refChild(component, { at, _ }) {
    const child = component.refChild(at);
    const $child = (0, Async_1.Async)(child, _, component.__system.async);
    return $child;
}
function $getAnimations(component, data, callback) {
    const animations = component.getAnimations();
    callback(animations);
}
function $getSetup(component, data, callback) {
    const setup = component.getSetup();
    callback(setup);
}
//# sourceMappingURL=$component.js.map