import { FieldSchema, StructureSchema } from '@ephox/boulder';
import { Obj } from '@ephox/katamari';
import * as FunctionAnnotator from '../../debugging/FunctionAnnotator';
import * as AlloyParts from '../../parts/AlloyParts';
import * as GuiTypes from './GuiTypes';
import * as UiSketcher from './UiSketcher';
export const isSketchSpec = (spec) => {
    return spec.uid !== undefined;
};
const singleSchema = StructureSchema.objOfOnly([
    FieldSchema.required('name'),
    FieldSchema.required('factory'),
    FieldSchema.required('configFields'),
    FieldSchema.defaulted('apis', {}),
    FieldSchema.defaulted('extraApis', {})
]);
const compositeSchema = StructureSchema.objOfOnly([
    FieldSchema.required('name'),
    FieldSchema.required('factory'),
    FieldSchema.required('configFields'),
    FieldSchema.required('partFields'),
    FieldSchema.defaulted('apis', {}),
    FieldSchema.defaulted('extraApis', {})
]);
const single = (rawConfig) => {
    const config = StructureSchema.asRawOrDie('Sketcher for ' + rawConfig.name, singleSchema, rawConfig);
    const sketch = (spec) => UiSketcher.single(config.name, config.configFields, config.factory, spec);
    const apis = Obj.map(config.apis, GuiTypes.makeApi);
    const extraApis = Obj.map(config.extraApis, (f, k) => FunctionAnnotator.markAsExtraApi(f, k));
    return {
        name: config.name,
        configFields: config.configFields,
        sketch,
        ...apis,
        ...extraApis
    };
};
const composite = (rawConfig) => {
    const config = StructureSchema.asRawOrDie('Sketcher for ' + rawConfig.name, compositeSchema, rawConfig);
    const sketch = (spec) => UiSketcher.composite(config.name, config.configFields, config.partFields, config.factory, spec);
    // These are constructors that will store their configuration.
    const parts = AlloyParts.generate(config.name, config.partFields);
    const apis = Obj.map(config.apis, GuiTypes.makeApi);
    const extraApis = Obj.map(config.extraApis, (f, k) => FunctionAnnotator.markAsExtraApi(f, k));
    return {
        name: config.name,
        partFields: config.partFields,
        configFields: config.configFields,
        sketch,
        parts,
        ...apis,
        ...extraApis
    };
};
export { single, composite };
//# sourceMappingURL=Sketcher.js.map