"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _ = require("lodash");
exports.ADD_UI_SCHEMA = 'jsonforms/treeWithDetail/ADD_UISCHEMA';
exports.SET_CONTAINER_PROPERTIES = 'jsonforms/treeWithDetail/SET_CONTAINER_PROPERTIES';
exports.getUiSchemata = function (state) { return extractUiSchemata(state.jsonforms.treeWithDetail); };
exports.getImageMapping = function (state) { return extractImageMapping(state.jsonforms.treeWithDetail); };
exports.getLabelMapping = function (state) { return extractLabelMapping(state.jsonforms.treeWithDetail); };
exports.getModelMapping = function (state) { return extractModelMapping(state.jsonforms.treeWithDetail); };
exports.getResources = function (state) { return extractResources(state.jsonforms.treeWithDetail); };
exports.getIdentifyingProperty = function (state) {
    return extractIdentifyingProperty(state.jsonforms.treeWithDetail);
};
exports.getContainerProperties = function (state) {
    return extractContainerProperties(state.jsonforms.treeWithDetail);
};
var extractUiSchemata = function (state) { return state.uiSchemata; };
var extractImageMapping = function (state) { return state.imageMapping; };
var extractLabelMapping = function (state) { return state.labelMapping; };
var extractModelMapping = function (state) { return state.modelMapping; };
var extractResources = function (state) { return state.resources; };
var extractIdentifyingProperty = function (state) { return state.identifyingProperty; };
var extractContainerProperties = function (state) { return state.containerProperties; };
// TODO Add action to add a resource when referencing is implemented
/**
 * Creates an action to add a detail UI schema for the Tree with detail.
 * If there already is a UI Schema for the given schema id,
 * it is overwritten with the given one.
 *
 * @param schemaId The JSON Schema's id for which the UI Schema will be used
 * @param uiSchema The UI Schema defining the rendered detail view
 */
exports.addUiSchema = function (schemaId, uiSchema) {
    return {
        type: exports.ADD_UI_SCHEMA,
        schemaId: schemaId,
        uiSchema: uiSchema
    };
};
/**
 * Creates an action to set calculated container properties for the given schema id
 * If there already are container properties for the given schema id
 * they are overwritten with the given one
 *
 * @param containerProperties
 * @returns {SetContainerPropertiesAction}
 */
exports.setContainerProperties = function (containerProperties) {
    return {
        type: exports.SET_CONTAINER_PROPERTIES,
        containerProperties: containerProperties
    };
};
exports.treeWithDetailReducer = function (state, action) {
    if (state === void 0) { state = {
        uiSchemata: {},
        containerProperties: {}
    }; }
    switch (action.type) {
        case exports.ADD_UI_SCHEMA:
            if (_.isEmpty(action.schemaId)) {
                return state;
            }
            if (action.uiSchema === undefined || action.uiSchema === null) {
                return state;
            }
            var uiSchemata = _.merge({}, state.uiSchemata, (_a = {}, _a[action.schemaId] = action.uiSchema, _a));
            return __assign({}, state, { uiSchemata: uiSchemata });
        case exports.SET_CONTAINER_PROPERTIES:
            return __assign({}, state, { containerProperties: action.containerProperties });
        default:
            return state;
    }
    var _a;
};
//# sourceMappingURL=index.js.map