<?php
/**
 * Segment preview page template
 *
 * @link       https://personalizewp.com/
 * @since      3.2.0 Merged into PWP
 * @since      1.0.0
 *
 * @package    PersonalizeWP
 * @subpackage PersonalizeWP/Admin
 *
 * @var PersonalizeWP\Model\Segment $segment The instance of the Segment class.
 */

namespace PersonalizeWP\Admin;

use PersonalizeWP\Admin\PageSegments;
use PersonalizeWP\Admin\ListTableContacts;

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

?>

	<main class="section entity-panel">
		<nav class="entity-panel__nav">
			<a href="<?php echo esc_url( admin_url( PageSegments::$index_url ) ); ?>" class="back">&larr; <?php esc_html_e( 'Back', 'personalizewp' ); ?></a>
		</nav>

		<section class="entity-panel__preview">
			<header class="entity-panel__header repel">
				<h2 class="section-title"><?php esc_html_e( 'Segment', 'personalizewp' ); ?></h2>

				<ul class="context-links">
					<li><a class="contextual-link" href="<?php echo esc_url( admin_url( PageSegments::$edit_url . $segment->ID ) ); ?>"><?php esc_html_e( 'Edit', 'personalizewp' ); ?></a></li>

					<?php if ( ! $segment->is_active ) : ?>
						<li><a href="<?php echo esc_url( wp_nonce_url( admin_url( PageSegments::$activate_url . $segment->ID ), 'activate-segment-' . $segment->ID ) ); ?>"><?php esc_html_e( 'Activate', 'personalizewp' ); ?></a></li>
					<?php else : ?>
						<li><a class="contextual-link" href="<?php echo esc_url( wp_nonce_url( admin_url( PageSegments::$deactivate_url . $segment->ID ), 'deactivate-segment-' . $segment->ID ) ); ?>"
							data-show-modal="#deactivateSegmentModal"><?php esc_html_e( 'Deactivate', 'personalizewp' ); ?></a></li>
					<?php endif; ?>

					<li><a class="contextual-link trash" href="<?php echo esc_url( wp_nonce_url( admin_url( PageSegments::$delete_url . $segment->ID ), 'delete-segment-' . $segment->ID ) ); ?>"
						data-show-modal="#deleteSegmentModal"><?php esc_html_e( 'Delete', 'personalizewp' ); ?></a></li>
				</ul>
			</header>

			<div class="pwp-panel">
				<table>
					<tbody>
					<tr>
						<th scope="row"><?php esc_html_e( 'Name', 'personalizewp' ); ?></th>
						<td><?php echo esc_html( $segment->name ); ?></td>
					</tr>
					<tr>
						<th scope="row"><?php esc_html_e( 'Type', 'personalizewp' ); ?></th>
						<td><?php echo esc_html( PageSegments::translate_type( $segment->type ) ); ?></td>
					</tr>
					<tr>
						<th scope="row"><?php esc_html_e( 'Size', 'personalizewp' ); ?></th>
						<td><?php echo esc_html( $segment->contact_count ); ?></td>
					</tr>
					</tbody>
				</table>
			</div>
		</section>

		<section class="entity-panel__activity">
			<header>
				<h2 class="pwp-panel__title mb-3"><?php esc_html_e( 'Visitor Profiles', 'personalizewp' ); ?></h2>
			</header>

			<?php
			$segment_contacts = new ListTableContacts();
			$segment_contacts->prepare_items();
			?>
			<form id="profiles-filter" method="get">
				<div class="table-actions">
					<?php
					$segment_contacts->search_box( __( 'Search Profiles', 'personalizewp' ), 'search-contacts' );
					?>
				</div>
				<?php
				$segment_contacts->display();
				?>
			</form>
		</section>
	</main>

<?php
require_once __DIR__ . '/_modal-deactivate.php';
require_once __DIR__ . '/_modal-delete.php';
