<?php

?>

<fieldset class="field-order-paper-publications">
	<?php
	// $choices = $this->buildChoices();
	$otherPublicationsArray = $this->buildChoicesArray();
	?>

	<?php foreach ($otherPublicationsArray as $index => $document) : ?>

		<?php
		// write_log($document);
		?>
		<?php
		$ID_FR = $document['ID_fr'];
		$ID_NL = $document['ID_nl'];

		$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143");
		$current_lang = apply_filters('wpml_current_language', null);
		$current_lang_id = $current_lang === 'nl' ? $ID_NL : $ID_FR;

		$documentPost =  get_post($current_lang_id);

		$metadata = wp_get_attachment_metadata($current_lang_id);
		?>

		<div class=" gchoice brochure-order-field">
			<div class="thematique-tag thematique-tag--general">
				<?php if ($thematiqueCover && $thematiqueCover['icon']) : ?>
					<img class="thematique-icon" src="<?php echo $thematiqueCover['icon']['url'] ?>" alt="">
				<?php endif; ?>
				<p>
					<?php echo __("Autre", "homegrade-theme__texte-fonctionnel") ?>

				</p>
			</div>
			<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $documentPost->post_title ?></legend>
			<a class="preview-brochure" href="<?php echo get_the_permalink($current_lang_id) ?>" target="_blank"><?php echo __("Voir le document", "homegrade-theme__texte-fonctionnel") ?></a>
			<div class="inputs-container">

				<div class="publications-amount-fr">
					<label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label>
					<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
				</div>
				<div class="publications-amount publications-amount-nl">
					<label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label>
					<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
				</div>
				<input type="hidden" name="<?php echo 'input_' . $current_lang_id . '[]' ?>" value="<?php echo $ID_FR ?>" />
				<input type="hidden" name="<?php echo 'input_' . $current_lang_id . '[]' ?>" value="<?php echo $ID_NL ?>" />

			</div>

			<?php if ($documentPost->post_content) : ?>
				<!-- <p class="legend"><?php echo  $documentPost->post_content ?></p> -->
			<?php endif; ?>


		</div>


		<div class="gchoice brochure-order-field">


		</div>
	<?php endforeach; ?>
</fieldset>