<?php

namespace Northmill_Online_Shared_Sync;

/**
 * Renders a repeater for a settings field.
 *
 * @package northmill-online-shared
 */
/**
 * View parameters.
 *
 * @var array $params
 */
?>

<table class="wp-list-table widefat striped table-view-list">
	<thead>
	<tr>
		<?php 
foreach ($params['field']['fields'] as $sub_field) {
    ?>
			<td><?php 
    echo \esc_html($sub_field['label']);
    ?></td>
			<?php 
}
?>
	</tr>
	</thead>
	<tbody>
	<?php 
for ($i = 0; $i < $params['field']['max_fields']; $i++) {
    ?>
		<tr>
			<?php 
    foreach ($params['field']['fields'] as $sub_field) {
        $sub_value = $params['value'][$i][$sub_field['name']] ?? $sub_field['default'];
        $sub_field['name'] = $params['field']['name'] . '_' . $sub_field['name'] . '_' . $i;
        ?>
				<td>
				<?php 
        $params['field_renderer'](array('field' => $sub_field, 'value' => $sub_value));
        ?>
					</td>
				<?php 
    }
    ?>
		</tr>
		<?php 
}
?>
	</tbody>
</table>
<?php 
