import { findByEditorID } from "@ax/forms";

const protectFormKeys = (content: any, key: string, editorID: number) => {
	const { parent: formComponent } = findByEditorID(content, editorID);
	if (!formComponent) return;

	if (!Array.isArray(formComponent.protectedKeys)) {
		formComponent.protectedKeys = [];
	}

	if (!formComponent.protectedKeys.includes(key)) {
		formComponent.protectedKeys.push(key);
	}

	return formComponent;
};

export { protectFormKeys };
