/*!
 * SAPUI5
 * (c) Copyright 2026 SAP SE. All rights reserved.
 */

// Provides the Design Time Metadata for the sap.ui.comp.smartform.Group control
sap.ui.define([
	"sap/ui/comp/delegates/FlexibilityDelegate",
	"sap/ui/rta/plugin/annotations/DocumentedAnnotationChanges"
], function(
	FlexibilityDelegate,
	DocumentedAnnotationChanges
) {
	"use strict";

	return {
		isVisible: function(oSmartForm) {
			// When DesignTime processes the SmartForm, trigger deferred invalidation
			// for groups added via flexibility changes that are currently hidden.
			// This ensures they become visible during Adapt UI so users can interact with them.
			// (Group.designtime.js tool.start cannot fire for these groups because they have no DOM yet.)
			oSmartForm.getGroups().forEach(function(oGroup) {
				if (oGroup.data("addedViaChange") === "true" && !oGroup.isVisible() && !oGroup._bDesignTimeInvalidatePending) {
					oGroup._bDesignTimeActive = true;
					oGroup._bDesignTimeInvalidatePending = true;
					setTimeout(function() {
						delete oGroup._bDesignTimeInvalidatePending;
						oGroup.invalidate();
					}, 0);
				}
			});
			return oSmartForm.getVisible();
		},
		actions: {
			localReset: "localReset",
			annotation:  function(oControl) {
				// In case we are in a SmartForm with no SmartFields we don't offer the option.
				if (
					oControl?.isA("sap.ui.comp.smartform.SmartForm") &&
					oControl.getSmartFields().length === 0
				) {
					return {};
				}

				return {
					[DocumentedAnnotationChanges.TextArrangement]: FlexibilityDelegate.getTextArrangementDelegate(oControl),
					[DocumentedAnnotationChanges.Rename]: FlexibilityDelegate.getLabelDelegate(oControl)
				};
			}
		},
		aggregations: {
			groups: {
				propagateRelevantContainer: true,

				childNames: {
					singular: "GROUP_CONTROL_NAME",
					plural: "GROUP_CONTROL_NAME_PLURAL"
				},
				actions: {
					move: "moveGroups",
					remove : {
						removeLastElement: true
					},
					createContainer: {
						changeType: "addGroup",
						isEnabled: true,
						getCreatedContainerId: function(sNewControlID) {
							return sNewControlID;
						}
					}
				}
			},
			customToolbar: {
				propagateMetadata : function (oElement) {
					if (oElement.isA(["sap.m.ToolbarSpacer", "sap.m.ToolbarSeparator"])) {
						return {
							actions: "not-adaptable"
						};
					}
				}
			}
		},
		name: {
			singular: "SMARTFORM_NAME",
			plural: "SMARTFORM_NAME_PLURAL"
		},
		properties: {
			title: {
				ignore: false
			},
			useHorizontalLayout: {
				ignore: true
			},
			horizontalLayoutGroupElementMinWidth: {
				ignore: true
			},
			checkButton: {
				ignore: false
			},
			entityType: {
				ignore: true
			},
			expandable: {
				ignore: false
			},
			expanded: {
				ignore: false
			},
			editTogglable: {
				ignore: false
			},
			editable: {
				ignore: false
			},
			ignoredFields: {
				ignore: true
			},
			flexEnabled: {
				ignore: true
			},
			validationMode: {
				ignore: true
			},
			importance: {
				ignore: true
			}
		}
	};

}, /* bExport= */true);
