<?php
/**
 * Makes available item value handler sub forms.
 *
 * @package EaLab\WP_Deployer
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! function_exists( 'deploy_sync_content__item_value_handlers' ) ) {
	/**
	 * Makes available item value handler sub forms.
	 */
	function deploy_sync_content__item_value_handler_subforms(): void {
		$ids_and_labels = deploy_sync_content__get_item_value_handlers();

		foreach ( $ids_and_labels as $id => $label ) {
			$path = DEPLOY_SYNC_CONTENT__PLUGIN_DIR . 'admin/partials/component/advanced-settings/item-value-handler-subform--' . $id . '.php';
			file_exists($path) && require_once $path;
		}
	}

	/**
	 * Writes all templates for the item value handler subforms.
	 */
	function deploy_sync_content__item_value_handler_subforms_write_templates(): void {
		deploy_sync_content__item_value_handler_subforms();

		$context = array( 'as_template' => true );

		$ids_and_labels = deploy_sync_content__get_item_value_handlers();

		foreach ( $ids_and_labels as $id => $label ) {
			$maybe_function_name = 'deploy_sync_content__item_value_handler_subform__' . $id;

			function_exists( $maybe_function_name ) && $maybe_function_name( $context );
		}
	}
}
