"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionsContainerAggregation = void 0;
const ux_specification_types_1 = require("@sap/ux-specification-types");
const ObjectAggregation_1 = require("../ObjectAggregation");
const types_1 = require("../types");
const ActionAggregation_1 = require("./ActionAggregation");
class ActionsContainerAggregation extends ObjectAggregation_1.ObjectAggregation {
    /**
     * Creates an instance of `ActionsContainerAggregation`.
     *
     * @param data Optional aggregation data object used to initialize properties.
     * @param schema Optional JSON schema fragment associated with this aggregation.
     */
    constructor(data, schema) {
        super(data, schema);
        this.sortableList = true;
        this.childClass = ActionAggregation_1.ActionAggregation;
        this.allowedAnnotationCreationForms = [types_1.AggregationCreationForm.NativeAction];
        this.sortableCollection = 'actions';
        this.i18nKey = 'ACTIONS';
        this.isNestedContainer = false; // Whether container is nested in another container (e.g. actions container within action group )
    }
    /**
     * Method adds aggregation object.
     * Overwritten to mark standard action.
     *
     * @param name Name of aggregation.
     * @param aggregation Aggregation to add.
     * @param path Array of path to aggregation.
     * @param order Order index.
     * @param overwrite Overwrite existing aggregation.
     * @returns Added aggregation.
     */
    addAggregation(name, aggregation, path, order, overwrite) {
        aggregation = super.addAggregation(name, aggregation, path, order, overwrite);
        if (aggregation instanceof ActionAggregation_1.ActionAggregation && aggregation.name) {
            switch (aggregation.schema?.actionType) {
                case ux_specification_types_1.ActionType.Standard: {
                    aggregation.markAsStandardAction();
                    break;
                }
                case ux_specification_types_1.ActionType.Copy: {
                    aggregation.sortableItem = types_1.SortingOptions.Readonly;
                    break;
                }
            }
        }
        return aggregation;
    }
    /**
     * Overwritten method for data update of object page actions
     * Method receives current values for actions and detects custom actions.
     *
     * @param data Data which should be used for value population.
     * @param page Page config data.
     * @param pageType Page type.
     * @param path Aggregation path.
     * @param annotations Annotations data.
     */
    updatePropertiesValues(data, page, pageType, path, annotations) {
        super.updatePropertiesValues(data, page, pageType, path, annotations);
        this.formSchema = this.additionalProperties?.aggregations['actions'];
        const actions = data || {};
        if (!actions['menu']) {
            for (const id in actions) {
                const action = this.aggregations[id];
                if (action?.name && action.schema?.actionType === 'Standard') {
                    action.markAsStandardAction();
                }
                else if (action?.schema &&
                    'markAsCustomAction' in action &&
                    (action.schema.actionType === 'Custom' ||
                        (!action.schema.annotationPath && action.schema.actionType !== 'CustomMenu'))) {
                    action.markAsCustomAction();
                }
            }
        }
    }
}
exports.ActionsContainerAggregation = ActionsContainerAggregation;
//# sourceMappingURL=ActionsContainerAggregation.js.map