import { Obj } from '@ephox/katamari';
import * as AlloyParts from '../../parts/AlloyParts';
import * as Tagger from '../../registry/Tagger';
import * as SpecSchema from '../../spec/SpecSchema';
const single = (owner, schema, factory, spec) => {
    const specWithUid = supplyUid(spec);
    const detail = SpecSchema.asRawOrDie(owner, schema, specWithUid, [], []);
    return factory(detail, specWithUid);
};
const composite = (owner, schema, partTypes, factory, spec) => {
    const specWithUid = supplyUid(spec);
    // Identify any information required for external parts
    const partSchemas = AlloyParts.schemas(partTypes);
    // Generate partUids for all parts (external and otherwise)
    const partUidsSchema = AlloyParts.defaultUidsSchema(partTypes);
    const detail = SpecSchema.asRawOrDie(owner, schema, specWithUid, partSchemas, [partUidsSchema]);
    // Create (internals, externals) substitutions
    const subs = AlloyParts.substitutes(owner, detail, partTypes);
    // Work out the components by substituting internals
    const components = AlloyParts.components(owner, detail, subs.internals());
    return factory(detail, components, specWithUid, subs.externals());
};
const hasUid = (spec) => Obj.has(spec, 'uid');
const supplyUid = (spec) => {
    return hasUid(spec) ? spec : {
        ...spec,
        uid: Tagger.generate('uid')
    };
};
export { supplyUid, single, composite };
//# sourceMappingURL=UiSketcher.js.map