<?php do_action( 'happyforms_poll_edit_screen_before' ); ?>

<?php
$polls_controller = happyforms_get_polls_controller();
$form_controller = happyforms_get_form_controller();

$form_id = happyforms_get_meta( $post->ID, 'form_id', true );
$form = $form_controller->get( $form_id );

$polls = $polls_controller->get_all_form_polls( $form );

$poll_id = happyforms_get_meta( $post->ID, 'poll_id', true );
$poll = $form_controller->get_part_by_id( $form, $poll_id );
$poll_post = $polls_controller->get_poll_by_id( $form, $poll_id );
?>
<div class="happyforms-poll-screen__poll">
	<?php include( happyforms_get_include_folder() . '/templates/admin-poll-table.php' ); ?>
</div>
<?php
$current_poll = $poll;
$poll = '';
?>

<?php
foreach ( $polls as $poll ) :
	if ( $poll['id'] !== $current_poll['id'] ) {
		$poll_post  = $polls_controller->get_poll_by_id( $form, $poll['id'] );
		$poll_title = get_the_title( $poll_post['ID'] );
		$poll_title = ( ! empty( $poll_title ) ) ? $poll_title : __( '(no label)', 'happyforms' );
		?>
		<div class="happyforms-poll-screen__poll">
			<h1 class="wp-heading-inline"><?php _e( 'Results for', 'happyforms' ); ?> "<?php echo $poll_title; ?>"</h1>
			<hr class="wp-header-end">
			<?php include( happyforms_get_include_folder() . '/templates/admin-poll-table.php' ); ?>
		</div>
		<?php
	}
endforeach;
?>

<?php do_action( 'happyforms_poll_edit_screen_after' ); ?>
