<?php

/**
 * Repeater content
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $wpcb_field;

$wpcb_repeater = $wpcb_field;
?>

<div class="wpcb-configurator-field wpcb-configurator-repeater">
	<div class="wpcb-configurator-repeater-title">
		<strong class="wpcb-configurator-repeater-label">
			<?php echo esc_attr( $wpcb_repeater['label'] ); ?>
		</strong>
	</div>

	<div class="wpcb-configurator-repeater-main">
		<p class="wpcb-configurator-repeater-empty-note"><?php echo esc_attr( $wpcb_repeater['empty_text'] ); ?></p>
		<div data-repeater-list="<?php echo esc_attr( $wpcb_repeater['id'] ); ?>" data-repeater-min="<?php echo esc_attr( $wpcb_repeater['min'] ); ?>" data-repeater-max="<?php echo esc_attr( $wpcb_repeater['max'] ); ?>">
			<div data-repeater-item class="wpcb-configurator-repeater-item<?php if ( $wpcb_repeater['collapsible'] ) echo ' collapsible'; ?>">
				<?php if ( $wpcb_repeater['collapsible'] ) : ?>
					<div class="wpcb-configurator-repeater-item-action">
						<a href="#0" class="wpcb-repeater-collapse">
							<span class="open">
								<?php echo wp_kses( wpcb_get_icon( 'minus' ), wpcb_get_icon_kses_args() ); ?>
							</span>
							<span class="closed">
								<?php echo wp_kses( wpcb_get_icon( 'plus' ), wpcb_get_icon_kses_args() ); ?>
							</span>
							<p><?php echo esc_attr( $wpcb_repeater['label'] ); ?><span class="index">1</span></p>
						</a>
						<button data-repeater-delete type="button" class="wpcb-repeater-delete">
							<?php echo wp_kses( wpcb_get_icon( 'bin' ), wpcb_get_icon_kses_args() ); ?>
						</button>
					</div>
				<?php endif; ?>
				<div class="wpcb-configurator-repeater-item-content">

					<?php
					foreach ( $wpcb_repeater['subfields'] as $wpcb_field ) {
						$wpcb_field['id'] = $wpcb_field['id'] . '-0';
						if ( isset( $wpcb_field['visual']['reference'] ) && '' !== $wpcb_field['visual']['reference'] ) {
							$wpcb_field['visual']['reference'] = $wpcb_field['visual']['reference'] . '-0';
						}

						if ( isset( $wpcb_field['options'] ) ) {
							include 'choice.php';
						} else {
							include 'input.php';
						}
					}
					?>

				</div>
				<?php if ( ! $wpcb_repeater['collapsible'] ) : ?>
					<div class="wpcb-configurator-repeater-item-action">
						<button data-repeater-delete type="button" class="wpcb-repeater-delete">
							<?php echo wp_kses( wpcb_get_icon( 'bin' ), wpcb_get_icon_kses_args() ); ?>
						</button>
					</div>
				<?php endif; ?>
			</div>
		</div>
		<div class="wpcb-configurator-repeater-footer">
			<button data-repeater-create type="button" class="wpcb-button wpcb-repeater-add">
				<?php echo esc_attr( $wpcb_repeater['add_text'] ); ?>
			</button>
		</div>
	</div>
</div>