//#region src/v2/blocks/request-block/helpers/create-parameter-handlers.ts
/** Create parameter event handlers for a given type */
var createParameterHandlers = (type, eventBus, meta, { context, defaultParameters = 0, globalParameters = 0 }) => {
	const offset = defaultParameters + globalParameters;
	return {
		delete: (payload) => {
			const originalParameter = context[payload.index]?.originalParameter;
			if (!originalParameter) return;
			eventBus.emit("operation:delete:parameter", {
				originalParameter,
				meta
			}, { skipUnpackProxy: true });
		},
		deleteAll: () => eventBus.emit("operation:delete-all:parameters", {
			type,
			meta
		}),
		upsert: (index, payload) => {
			const row = context[index];
			if (index < defaultParameters + globalParameters) {
				const extraParameterType = index < defaultParameters ? "default" : "global";
				return eventBus.emit("operation:update:extra-parameters", {
					type: extraParameterType,
					in: type,
					meta: {
						...meta,
						name: row?.name?.toLowerCase?.() ?? "NON_VALID"
					},
					payload: { isDisabled: payload.isDisabled ?? false }
				});
			}
			if (index >= offset) return eventBus.emit("operation:upsert:parameter", {
				type,
				payload,
				originalParameter: row?.originalParameter ?? null,
				meta
			}, {
				skipUnpackProxy: true,
				debounceKey: `update:parameter-${type}-${index - offset}`
			});
		}
	};
};
//#endregion
export { createParameterHandlers };

//# sourceMappingURL=create-parameter-handlers.js.map