<?php
/** Shared contract for verified Ocean Extra per-post layout-adjacent overrides. */

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

define( 'WPAGENT_OCEAN_EXTRA_LAYOUT_THEME_VERSION', '4.2.2' );
define( 'WPAGENT_OCEAN_EXTRA_LAYOUT_MAX_CONTENT_WIDTH', 100 );

/** @return array<string,array{meta:string,values:array<string,string>}> */
function wpagent_oceanwp_extra_layout_choice_catalog(): array {
	return array(
		'header_visibility' => array(
			'meta'   => 'ocean_display_header',
			'values' => array( 'show' => 'on', 'hide' => 'off' ),
		),
		'header_style'      => array(
			'meta'   => 'ocean_header_style',
			'values' => array(
				'minimal'     => 'minimal',
				'transparent' => 'transparent',
				'top'         => 'top',
				'full_screen' => 'full_screen',
				'center'      => 'center',
				'medium'      => 'medium',
				'vertical'    => 'vertical',
			),
		),
		'footer_widgets'    => array(
			'meta'   => 'ocean_display_footer_widgets',
			'values' => array( 'show' => 'on', 'hide' => 'off' ),
		),
		'footer_bottom'     => array(
			'meta'   => 'ocean_display_footer_bottom',
			'values' => array( 'show' => 'on', 'hide' => 'off' ),
		),
	);
}

/** @return array<string,array{meta:string}> */
function wpagent_oceanwp_extra_layout_meta_catalog(): array {
	$catalog = wpagent_oceanwp_extra_layout_choice_catalog();
	$catalog['custom_sidebar'] = array( 'meta' => 'ocean_sidebar' );
	$catalog['content_width']  = array( 'meta' => 'ocean_both_sidebars_content_width' );
	$catalog['content_layout'] = array( 'meta' => 'ocean_post_layout' );
	return $catalog;
}

/** @return array<string,mixed> */
function wpagent_oceanwp_extra_layout_header_schema( bool $complete = false ): array {
	$schema = array(
		'type'                 => 'object',
		'properties'           => array(
			'visibility' => array( 'type' => 'string', 'enum' => array( 'inherit', 'show', 'hide' ) ),
			'style'      => array( 'type' => 'string', 'enum' => array_merge( array( 'inherit' ), array_keys( wpagent_oceanwp_extra_layout_choice_catalog()['header_style']['values'] ) ) ),
		),
		'additionalProperties' => false,
	);
	if ( $complete ) {
		$schema['required'] = array( 'visibility', 'style' );
	} else {
		$schema['minProperties'] = 1;
		$schema['maxProperties'] = 2;
	}
	return $schema;
}

/** @return array<string,mixed> */
function wpagent_oceanwp_extra_layout_footer_schema( bool $complete = false ): array {
	$schema = array(
		'type'                 => 'object',
		'properties'           => array(
			'widgets' => array( 'type' => 'string', 'enum' => array( 'inherit', 'show', 'hide' ) ),
			'bottom'  => array( 'type' => 'string', 'enum' => array( 'inherit', 'show', 'hide' ) ),
		),
		'additionalProperties' => false,
	);
	if ( $complete ) {
		$schema['required'] = array( 'widgets', 'bottom' );
	} else {
		$schema['minProperties'] = 1;
		$schema['maxProperties'] = 2;
	}
	return $schema;
}

/** @return array<string,mixed> */
function wpagent_oceanwp_extra_layout_sidebar_schema(): array {
	return array(
		'type'                 => 'object',
		'properties'           => array(
			'mode'       => array( 'type' => 'string', 'enum' => array( 'inherit', 'set' ) ),
			'sidebar_id' => array( 'type' => 'string', 'minLength' => 1, 'maxLength' => 120, 'pattern' => '^[a-z0-9_-]+$' ),
		),
		'required'             => array( 'mode' ),
		'additionalProperties' => false,
	);
}

/** @return array<string,mixed> */
function wpagent_oceanwp_extra_layout_width_schema(): array {
	return array(
		'type'                 => 'object',
		'properties'           => array(
			'mode'  => array( 'type' => 'string', 'enum' => array( 'inherit', 'set' ) ),
			'value' => array( 'type' => 'integer', 'minimum' => 1, 'maximum' => WPAGENT_OCEAN_EXTRA_LAYOUT_MAX_CONTENT_WIDTH ),
		),
		'required'             => array( 'mode' ),
		'additionalProperties' => false,
	);
}

/** @return array<string,mixed> */
function wpagent_oceanwp_extra_layout_state_schema(): array {
	return array(
		'type'                 => 'object',
		'properties'           => array(
			'header'         => wpagent_oceanwp_extra_layout_header_schema( true ),
			'footer'         => wpagent_oceanwp_extra_layout_footer_schema( true ),
			'custom_sidebar' => wpagent_oceanwp_extra_layout_sidebar_schema(),
			'content_width'  => wpagent_oceanwp_extra_layout_width_schema(),
		),
		'required'             => array( 'header', 'footer', 'custom_sidebar', 'content_width' ),
		'additionalProperties' => false,
	);
}

/** @return array<string,mixed> */
function wpagent_oceanwp_extra_layout_settings_schema(): array {
	return array(
		'type'                 => 'object',
		'properties'           => array(
			'header'         => wpagent_oceanwp_extra_layout_header_schema(),
			'footer'         => wpagent_oceanwp_extra_layout_footer_schema(),
			'custom_sidebar' => wpagent_oceanwp_extra_layout_sidebar_schema(),
			'content_width'  => wpagent_oceanwp_extra_layout_width_schema(),
		),
		'minProperties'        => 1,
		'maxProperties'        => 4,
		'additionalProperties' => false,
	);
}

function wpagent_oceanwp_extra_layout_runtime_ready(): bool {
	return wpagent_oceanwp_runtime_ready()
		&& class_exists( 'Ocean_Extra' )
		&& WPAGENT_OCEAN_EXTRA_LAYOUT_THEME_VERSION === wpagent_oceanwp_version()
		&& WPAGENT_OCEAN_EXTRA_MIN_VERSION === wpagent_oceanwp_extra_version()
		&& class_exists( 'OceanWP_Post_Settings_Output' )
		&& function_exists( 'oceanwp_display_header' )
		&& function_exists( 'oceanwp_header_style' )
		&& function_exists( 'oceanwp_display_footer_widgets' )
		&& function_exists( 'oceanwp_display_footer_bottom' )
		&& function_exists( 'oceanwp_get_sidebar' );
}

/** @return true|WP_Error */
function wpagent_oceanwp_extra_layout_require_runtime() {
	if ( ! wpagent_oceanwp_is_active() ) {
		return new WP_Error( 'wpagent_oceanwp_inactive', __( 'OceanWP oder ein OceanWP-Child-Theme ist nicht aktiv.', 'wp-agent-companion' ), array( 'status' => 409 ) );
	}
	if ( ! wpagent_oceanwp_extra_layout_runtime_ready() ) {
		return new WP_Error( 'wpagent_ocean_extra_layout_runtime_missing', __( 'Der geprüfte Header-, Footer-, Sidebar- und Breitenweg erfordert genau OceanWP 4.2.2 und Ocean Extra 2.5.8.', 'wp-agent-companion' ), array( 'status' => 409 ) );
	}
	return true;
}

/** @return array{post:WP_Post,blog_id:int}|WP_Error */
function wpagent_oceanwp_extra_layout_post_target( int $post_id, ?int $expected_blog_id = null ) {
	$blog_id = (int) get_current_blog_id();
	if ( $blog_id < 1 || ( null !== $expected_blog_id && $blog_id !== $expected_blog_id ) ) {
		return new WP_Error( 'wpagent_ocean_extra_layout_site_changed', __( 'Die Websitezuordnung hat sich während des Ocean-Extra-Vorgangs geändert.', 'wp-agent-companion' ), array( 'status' => 409 ) );
	}
	$post = wpagent_oceanwp_post_target( $post_id );
	if ( is_wp_error( $post ) ) {
		return $post;
	}
	return array( 'post' => $post, 'blog_id' => $blog_id );
}

function wpagent_oceanwp_extra_layout_sidebar_is_safe( string $sidebar_id ): bool {
	global $wp_registered_sidebars;
	return '' !== $sidebar_id
		&& sanitize_key( $sidebar_id ) === $sidebar_id
		&& isset( $wp_registered_sidebars[ $sidebar_id ] )
		&& is_active_sidebar( $sidebar_id );
}

function wpagent_oceanwp_extra_layout_content_width_is_safe( string $value ): bool {
	if ( '' === $value ) {
		return true;
	}
	if ( ! ctype_digit( $value ) ) {
		return false;
	}
	$width = (int) $value;
	return $width >= 0 && $width <= WPAGENT_OCEAN_EXTRA_LAYOUT_MAX_CONTENT_WIDTH;
}

function wpagent_oceanwp_extra_layout_raw_value_is_safe( string $field, string $value ): bool {
	if ( 'custom_sidebar' === $field ) {
		return '' === $value || wpagent_oceanwp_extra_layout_sidebar_is_safe( $value );
	}
	if ( 'content_width' === $field ) {
		return wpagent_oceanwp_extra_layout_content_width_is_safe( $value );
	}
	if ( 'content_layout' === $field ) {
		return '' === $value || in_array( $value, array( 'right-sidebar', 'left-sidebar', 'full-width', 'full-screen', 'both-sidebars' ), true );
	}
	$catalog = wpagent_oceanwp_extra_layout_choice_catalog();
	if ( ! isset( $catalog[ $field ] ) ) {
		return false;
	}
	if ( '' === $value ) {
		return true;
	}
	if ( in_array( $field, array( 'header_visibility', 'footer_widgets', 'footer_bottom' ), true ) && 'default' === $value ) {
		return true;
	}
	return in_array( $value, $catalog[ $field ]['values'], true );
}

/**
 * @return array{post_id:int,post_type:string,blog_id:int,version:string,meta:array<string,array{exists:bool,value:string}>}|WP_Error
 */
function wpagent_oceanwp_extra_layout_snapshot( WP_Post $post, int $blog_id ) {
	if ( $blog_id < 1 || (int) get_current_blog_id() !== $blog_id ) {
		return new WP_Error( 'wpagent_ocean_extra_layout_site_changed', __( 'Die Websitezuordnung hat sich während des Ocean-Extra-Vorgangs geändert.', 'wp-agent-companion' ), array( 'status' => 409 ) );
	}
	$fresh_post = get_post( $post->ID );
	if ( ! $fresh_post instanceof WP_Post || $fresh_post->post_type !== $post->post_type ) {
		return new WP_Error( 'wpagent_ocean_extra_layout_post_changed', __( 'Der Beitrag ist nicht mehr im gelesenen Zustand vorhanden.', 'wp-agent-companion' ), array( 'status' => 409 ) );
	}
	$version = wpagent_oceanwp_extra_version();
	if ( WPAGENT_OCEAN_EXTRA_MIN_VERSION !== $version || WPAGENT_OCEAN_EXTRA_LAYOUT_THEME_VERSION !== wpagent_oceanwp_version() ) {
		return new WP_Error( 'wpagent_ocean_extra_layout_provider_changed', __( 'Die Ocean-Extra-Version hat sich während des Vorgangs geändert.', 'wp-agent-companion' ), array( 'status' => 409 ) );
	}
	$meta = array();
	foreach ( wpagent_oceanwp_extra_layout_meta_catalog() as $field => $definition ) {
		$key  = $definition['meta'];
		$raw  = get_metadata_raw( 'post', $post->ID, $key, false );
		$rows = null === $raw ? array() : ( is_array( $raw ) ? $raw : array( $raw ) );
		if ( count( $rows ) > 1 ) {
			return new WP_Error( 'wpagent_ocean_extra_layout_duplicate_state', __( 'Der Beitrag enthält doppelte Ocean-Extra-Layoutmetadaten und kann nicht sicher bearbeitet werden.', 'wp-agent-companion' ), array( 'status' => 502 ) );
		}
		$exists = 1 === count( $rows );
		$value  = $exists ? $rows[0] : '';
		if ( $exists && ! is_string( $value ) ) {
			return new WP_Error( 'wpagent_ocean_extra_layout_invalid_state', __( 'Der Beitrag enthält einen ungültigen Ocean-Extra-Layoutzustand.', 'wp-agent-companion' ), array( 'status' => 502 ) );
		}
		if ( $exists && ! wpagent_oceanwp_extra_layout_raw_value_is_safe( $field, (string) $value ) ) {
			return new WP_Error( 'wpagent_ocean_extra_layout_invalid_state', __( 'Der Beitrag enthält einen nicht sicher auswertbaren Ocean-Extra-Layoutzustand.', 'wp-agent-companion' ), array( 'status' => 502 ) );
		}
		$meta[ $key ] = array( 'exists' => $exists, 'value' => (string) $value );
	}
	return array(
		'post_id'   => (int) $fresh_post->ID,
		'post_type' => $fresh_post->post_type,
		'blog_id'   => $blog_id,
		'version'   => $version,
		'meta'      => $meta,
	);
}

/**
 * @param array{post_id:int,post_type:string,blog_id:int,version:string,meta:array<string,array{exists:bool,value:string}>} $snapshot
 * @return array{header:array{visibility:string,style:string},footer:array{widgets:string,bottom:string},custom_sidebar:array{mode:string,sidebar_id?:string},content_width:array{mode:string,value?:int}}
 */
function wpagent_oceanwp_extra_layout_normalize( array $snapshot ): array {
	$catalog = wpagent_oceanwp_extra_layout_choice_catalog();
	$choice  = static function ( string $field ) use ( $snapshot, $catalog ): string {
		$entry = $snapshot['meta'][ $catalog[ $field ]['meta'] ];
		$value = $entry['exists'] ? $entry['value'] : '';
		if ( '' === $value || 'default' === $value ) {
			return 'inherit';
		}
		return (string) array_search( $value, $catalog[ $field ]['values'], true );
	};
	$sidebar = $snapshot['meta']['ocean_sidebar'];
	$width   = $snapshot['meta']['ocean_both_sidebars_content_width'];
	return array(
		'header'         => array( 'visibility' => $choice( 'header_visibility' ), 'style' => $choice( 'header_style' ) ),
		'footer'         => array( 'widgets' => $choice( 'footer_widgets' ), 'bottom' => $choice( 'footer_bottom' ) ),
		'custom_sidebar' => ( $sidebar['exists'] && '' !== $sidebar['value'] ) ? array( 'mode' => 'set', 'sidebar_id' => $sidebar['value'] ) : array( 'mode' => 'inherit' ),
		'content_width'  => ( $width['exists'] && (int) $width['value'] > 0 ) ? array( 'mode' => 'set', 'value' => (int) $width['value'] ) : array( 'mode' => 'inherit' ),
	);
}

/** @param array{post_id:int,post_type:string,blog_id:int,version:string,meta:array<string,array{exists:bool,value:string}>} $snapshot */
function wpagent_oceanwp_extra_layout_state_hash( array $snapshot ): string {
	$parent = wp_get_theme( get_template() );
	$child  = wp_get_theme( get_stylesheet() );
	$state  = get_template() . '@' . $parent->get( 'Version' ) . '|' . get_stylesheet() . '@' . $child->get( 'Version' );
	$state .= '|ocean-extra@' . $snapshot['version'] . "\0" . $snapshot['blog_id'] . "\0" . $snapshot['post_id'] . "\0" . $snapshot['post_type'];
	foreach ( $snapshot['meta'] as $key => $entry ) {
		$state .= "\0" . $key . "\0" . ( $entry['exists'] ? '1' : '0' ) . "\0" . $entry['value'];
	}
	return hash( 'sha256', $state );
}

/** @param array<string,mixed> $settings */
function wpagent_oceanwp_extra_layout_settings_are_safe( array $settings ): bool {
	foreach ( array( 'header' => array( 'visibility', 'style' ), 'footer' => array( 'widgets', 'bottom' ) ) as $group => $fields ) {
		if ( ! array_key_exists( $group, $settings ) ) {
			continue;
		}
		if ( ! is_array( $settings[ $group ] ) || ! $settings[ $group ] ) {
			return false;
		}
		foreach ( $fields as $field ) {
			if ( ! array_key_exists( $field, $settings[ $group ] ) ) {
				continue;
			}
			if ( ! is_string( $settings[ $group ][ $field ] ) ) {
				return false;
			}
			if ( 'header' === $group && 'style' === $field ) {
				if ( ! in_array( $settings[ $group ][ $field ], array_merge( array( 'inherit' ), array_keys( wpagent_oceanwp_extra_layout_choice_catalog()['header_style']['values'] ) ), true ) ) {
					return false;
				}
			} elseif ( ! in_array( $settings[ $group ][ $field ], array( 'inherit', 'show', 'hide' ), true ) ) {
				return false;
			}
		}
	}
	if ( array_key_exists( 'custom_sidebar', $settings ) ) {
		$sidebar = $settings['custom_sidebar'];
		if ( ! is_array( $sidebar ) || ! isset( $sidebar['mode'] ) || ! is_string( $sidebar['mode'] ) ) {
			return false;
		}
		if ( 'inherit' === $sidebar['mode'] ) {
			if ( array_key_exists( 'sidebar_id', $sidebar ) ) {
				return false;
			}
		} elseif ( 'set' !== $sidebar['mode'] || ! isset( $sidebar['sidebar_id'] ) || ! is_string( $sidebar['sidebar_id'] ) || ! wpagent_oceanwp_extra_layout_sidebar_is_safe( $sidebar['sidebar_id'] ) ) {
			return false;
		}
	}
	if ( array_key_exists( 'content_width', $settings ) ) {
		$width = $settings['content_width'];
		if ( ! is_array( $width ) || ! isset( $width['mode'] ) || ! is_string( $width['mode'] ) ) {
			return false;
		}
		if ( 'inherit' === $width['mode'] ) {
			if ( array_key_exists( 'value', $width ) ) {
				return false;
			}
		} elseif ( 'set' !== $width['mode'] || ! array_key_exists( 'value', $width ) || ! is_int( $width['value'] ) || $width['value'] < 1 || $width['value'] > WPAGENT_OCEAN_EXTRA_LAYOUT_MAX_CONTENT_WIDTH ) {
			return false;
		}
	}
	return true;
}

/**
 * @param array{post_id:int,post_type:string,blog_id:int,version:string,meta:array<string,array{exists:bool,value:string}>} $snapshot
 * @param array<string,mixed> $settings
 * @return array{post_id:int,post_type:string,blog_id:int,version:string,meta:array<string,array{exists:bool,value:string}>}
 */
function wpagent_oceanwp_extra_layout_expected_snapshot( array $snapshot, array $settings ): array {
	$expected = $snapshot;
	$catalog  = wpagent_oceanwp_extra_layout_choice_catalog();
	foreach ( array( 'header' => array( 'visibility' => 'header_visibility', 'style' => 'header_style' ), 'footer' => array( 'widgets' => 'footer_widgets', 'bottom' => 'footer_bottom' ) ) as $group => $fields ) {
		if ( ! isset( $settings[ $group ] ) || ! is_array( $settings[ $group ] ) ) {
			continue;
		}
		foreach ( $fields as $input_field => $catalog_field ) {
			if ( ! array_key_exists( $input_field, $settings[ $group ] ) ) {
				continue;
			}
			$key   = $catalog[ $catalog_field ]['meta'];
			$value = $settings[ $group ][ $input_field ];
			$expected['meta'][ $key ] = 'inherit' === $value
				? array( 'exists' => false, 'value' => '' )
				: array( 'exists' => true, 'value' => $catalog[ $catalog_field ]['values'][ $value ] );
		}
	}
	if ( isset( $settings['custom_sidebar'] ) ) {
		$sidebar = $settings['custom_sidebar'];
		$expected['meta']['ocean_sidebar'] = 'inherit' === $sidebar['mode']
			? array( 'exists' => false, 'value' => '' )
			: array( 'exists' => true, 'value' => $sidebar['sidebar_id'] );
	}
	if ( isset( $settings['content_width'] ) ) {
		$width = $settings['content_width'];
		$expected['meta']['ocean_both_sidebars_content_width'] = 'inherit' === $width['mode']
			? array( 'exists' => false, 'value' => '' )
			: array( 'exists' => true, 'value' => (string) $width['value'] );
	}
	return $expected;
}

/** @return array{header_visibility:bool,header_style:string,footer_widgets:bool,footer_bottom:bool,custom_sidebar:string,content_width_applied:bool}|WP_Error */
function wpagent_oceanwp_extra_layout_runtime_state( int $post_id, int $content_width ): array|WP_Error {
	if ( ! wpagent_oceanwp_extra_layout_runtime_ready() ) {
		return new WP_Error( 'wpagent_ocean_extra_layout_runtime_missing', __( 'Ocean Extra stellt den geprüften Layoutweg nicht bereit.', 'wp-agent-companion' ), array( 'status' => 409 ) );
	}
	$target = static fn( $current_id = null ) => $post_id;
	add_filter( 'ocean_post_id', $target, PHP_INT_MAX );
	try {
		$css = OceanWP_Post_Settings_Output::head_css( '' );
		$state = array(
			'header_visibility'    => oceanwp_display_header(),
			'header_style'         => oceanwp_header_style(),
			'footer_widgets'       => oceanwp_display_footer_widgets(),
			'footer_bottom'        => oceanwp_display_footer_bottom(),
			'custom_sidebar'       => oceanwp_get_sidebar(),
			'content_width_applied' => str_contains( $css, '.content-both-sidebars .content-area {width: ' . $content_width . '%;}' ),
		);
		if ( ! is_bool( $state['header_visibility'] ) || ! is_string( $state['header_style'] ) || ! is_bool( $state['footer_widgets'] ) || ! is_bool( $state['footer_bottom'] ) || ! is_string( $state['custom_sidebar'] ) ) {
			throw new UnexpectedValueException( 'Ocean Extra returned an invalid layout runtime state.' );
		}
		return $state;
	} catch ( Throwable $error ) {
		return new WP_Error( 'wpagent_ocean_extra_layout_runtime_failed', __( 'Ocean Extra konnte die Layout-Laufzeitwirkung nicht auswerten.', 'wp-agent-companion' ), array( 'status' => 502 ) );
	} finally {
		remove_filter( 'ocean_post_id', $target, PHP_INT_MAX );
	}
}

/**
 * @param array<string,mixed> $settings
 * @param array{header_visibility:bool,header_style:string,footer_widgets:bool,footer_bottom:bool,custom_sidebar:string,content_width_applied:bool} $runtime
 */
function wpagent_oceanwp_extra_layout_runtime_matches( array $settings, array $runtime ): bool {
	if ( isset( $settings['header']['visibility'] ) && 'inherit' !== $settings['header']['visibility'] && $runtime['header_visibility'] !== ( 'show' === $settings['header']['visibility'] ) ) {
		return false;
	}
	if ( isset( $settings['header']['style'] ) && 'inherit' !== $settings['header']['style'] && $runtime['header_style'] !== $settings['header']['style'] ) {
		return false;
	}
	if ( isset( $settings['footer']['widgets'] ) && 'inherit' !== $settings['footer']['widgets'] && $runtime['footer_widgets'] !== ( 'show' === $settings['footer']['widgets'] ) ) {
		return false;
	}
	if ( isset( $settings['footer']['bottom'] ) && 'inherit' !== $settings['footer']['bottom'] && $runtime['footer_bottom'] !== ( 'show' === $settings['footer']['bottom'] ) ) {
		return false;
	}
	if ( isset( $settings['custom_sidebar'] ) && 'set' === $settings['custom_sidebar']['mode'] && $runtime['custom_sidebar'] !== $settings['custom_sidebar']['sidebar_id'] ) {
		return false;
	}
	if ( isset( $settings['content_width'] ) && $runtime['content_width_applied'] !== ( 'set' === $settings['content_width']['mode'] ) ) {
		return false;
	}
	return true;
}

/** @return WP_Error */
function wpagent_oceanwp_extra_layout_recovery_required( int $post_id, int $blog_id ) {
	$target   = wpagent_oceanwp_extra_layout_post_target( $post_id, $blog_id );
	$snapshot = is_array( $target ) ? wpagent_oceanwp_extra_layout_snapshot( $target['post'], $target['blog_id'] ) : null;
	$data     = array( 'status' => 500, 'rollback_verified' => false, 'recovery_required' => true );
	if ( is_array( $snapshot ) ) {
		$data['current_hash']      = wpagent_oceanwp_extra_layout_state_hash( $snapshot );
		$data['current_overrides'] = wpagent_oceanwp_extra_layout_normalize( $snapshot );
	}
	return new WP_Error( 'wpagent_ocean_extra_layout_recovery_required', __( 'Die Ocean-Extra-Layoutänderung wurde nicht vollständig verifiziert. Es wurde kein automatisches Rollback ausgeführt. Wiederhole den Vorgang nicht automatisch und prüfe den aktuellen Zustand manuell.', 'wp-agent-companion' ), $data );
}
