<?php
/**
 * Brentwood house default: new Kadence Row Layout blocks use equal-height
 * columns ("Inner column height: 100%"). This lets an image column fill the
 * height of a taller text column beside it (pairs with the "Cover (fill column)"
 * image style) without authors touching settings.
 *
 * Two halves that must agree:
 *   - FRONT END (here): flip the registered default of kadence/rowlayout's
 *     `columnsInnerHeight` attribute to true.
 *   - EDITOR (assets/bw-row-defaults.js): flip the same client-side default.
 *
 * Note: because this is a registered DEFAULT (not a per-block value), it also
 * applies to existing rows that never explicitly set the option — i.e. it is
 * effectively retroactive. With the default column vertical alignment ("top")
 * that only equalises column heights (content stays top-aligned), so it's a
 * safe normalisation. Any row that should NOT be equal-height can be switched
 * off individually (Row → Inner column height), which serialises an explicit
 * `false` that overrides this default.
 *
 * @package Kadence-Child
 */

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

/* Front-end default. */
add_filter(
	'register_block_type_args',
	function ( $args, $name ) {
		if ( 'kadence/rowlayout' === $name && isset( $args['attributes']['columnsInnerHeight'] ) ) {
			$args['attributes']['columnsInnerHeight']['default'] = true;
		}
		return $args;
	},
	20,
	2
);

/* Editor default — load the filter before Kadence registers the row block. */
add_action(
	'enqueue_block_editor_assets',
	function () {
		$theme = get_stylesheet_directory();
		$file  = $theme . '/assets/bw-row-defaults.js';
		if ( ! file_exists( $file ) ) {
			return;
		}
		wp_enqueue_script(
			'bw-row-defaults',
			get_stylesheet_directory_uri() . '/assets/bw-row-defaults.js',
			array( 'wp-blocks', 'wp-hooks' ),
			filemtime( $file ),
			true
		);
	},
	1
);
