<?php
/**
 * Subform for the "option" item value handler.
 *
 * @package EaLab\WP_Deployer
 */

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

if ( ! function_exists( 'deploy_sync_content__item_value_handler_subform__option' ) ) {
	/**
	 * Subform for the "option" item value handler.
	 *
	 * @param array|null $context The context to build this component:
	 *     - "as_template" (bool): Set to true to build a template instead of the real markup.
	 *     - "for_table" (string): Table for this subform.
	 *     - "for_field" (string): Field for this subform.
	 *     - "item_value_handler_item" (array): The item value handler values.
	 */
	function deploy_sync_content__item_value_handler_subform__option( ?array $context = array() ): void {
		$as_template = $context['as_template'] ?? false;
		?>
		<div
			class="deploy-sync-content--settings--item-value-handler-subform--option"
			<?php echo esc_attr( $as_template ? 'data-dtt-template' : '' ); ?>>
			<label>
				<?php echo esc_html__( 'Field which contains the key', 'deploy-sync-content' ); ?>
				<?php if ( $as_template ) : ?>
					<dtt-dynamic-tag-template
						data-dtt-html-tag="input"
						data-dtt-format-attrs="name"
						data-dtt-format-attr-name="for_table,for_field"
						name="deploy_sync_content__settings_fieldtable_ivh[{for_table}][{for_field}][option_name_field_name]"
						type="text"
						value="">
					</dtt-dynamic-tag-template>
				<?php else : ?>
					<input
						name="deploy_sync_content__settings_fieldtable_ivh[<?php echo esc_attr( $context['for_table'] ?? '' ); ?>][<?php echo esc_attr( $context['for_field'] ?? '' ); ?>][option_name_field_name]"
						type="text"
						value="<?php echo esc_attr( $context['item_value_handler_item']['option_name_field_name'] ?? '' ); ?>">
				<?php endif; ?>
			</label>
		</div>
		<?php
	}
}
