<?php
/**
 * Meta box template for Actirise Ad Control
 *
 * @link       https://actirise.com
 * @since      3.2.0
 * @package    actirise
 * @subpackage actirise/admin/views
 * @author     actirise <wordpress@actirise.com>
 *
 * @var int  $post_id     The post ID.
 * @var bool $ads_enabled Whether ads are enabled for this post.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
?>

<style>
	#actirise-ad-control h2 {
		justify-content: flex-start;
	}
	#actirise-ad-control h2::before {
		content: '';
		display: inline-block;
		width: 16px;
		height: 16px;
		margin-right: 8px;
		background-image: url('<?php echo esc_url( ACTIRISE_URL . 'admin/assets/images/icon-actirise.png' ); ?>');
		background-size: contain;
		background-repeat: no-repeat;
		background-position: center;
		vertical-align: middle;
	}
	#actirise-ad-control .inside {
		margin: 0;
	}
	.actirise-toggle-field {
		margin: 15px 0;
	}
	.actirise-toggle {
		display: flex;
		align-items: center;
		cursor: pointer;
	}
	.actirise-toggle-slider {
		position: relative;
		display: inline-block;
		width: 3rem;
		height: 1.7rem;
		background-color: #e1e5e9;
		border-radius: 1rem;
		margin-right: 12px;
		transition: all 0.3s ease;
		cursor: pointer;
	}
	.actirise-toggle-slider:before {
		content: '';
		position: absolute;
		top: 5px;
		left: 4px;
		width: 17px;
		height: 17px;
		background-color: white;
		border-radius: 50%;
		transition: all 0.3s ease;
		box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
	}
	.actirise-toggle-input {
		display: none !important;
	}
	.actirise-toggle-input:checked + .actirise-toggle-slider {
		background: linear-gradient(
			86.4deg,
			#0093fd 0.04%,
			#5b71ff 33.01%,
			#956eff 65.49%,
			#f067d8 99.96%
		);
	}
	.actirise-toggle-input:checked + .actirise-toggle-slider:before {
		transform: translateX(1.4rem);
	}
	.actirise-toggle-label {
		font-weight: 600;
		color: #1d2327;
	}
	.actirise-toggle-off {
		display: none;
	}
	.actirise-toggle-input:checked ~ .actirise-toggle-label .actirise-toggle-on {
		display: inline;
	}
	.actirise-toggle-input:checked ~ .actirise-toggle-label .actirise-toggle-off {
		display: none;
	}
	.actirise-toggle-input:not(:checked) ~ .actirise-toggle-label .actirise-toggle-on {
		display: none;
	}
	.actirise-toggle-input:not(:checked) ~ .actirise-toggle-label .actirise-toggle-off {
		display: inline;
	}
	.actirise-info-text p {
		margin: 0;
	}
</style>

<?php wp_nonce_field( 'actirise_ad_control_nonce', 'actirise_ad_control_nonce' ); ?>

<div class="actirise-toggle-field">
	<label class="actirise-toggle">
		<input type="hidden" name="actirise_ads_enabled" value="0" />
		<input 
			type="checkbox" 
			name="actirise_ads_enabled" 
			value="1" 
			<?php checked( $ads_enabled ); ?>
			class="actirise-toggle-input"
		/>
		<span class="actirise-toggle-slider"></span>
		<span class="actirise-toggle-label">
			<span class="actirise-toggle-on"><?php esc_html_e( 'Ads are displaying', 'actirise' ); ?></span>
			<span class="actirise-toggle-off"><?php esc_html_e( 'Ads are excluded', 'actirise' ); ?></span>
		</span>
	</label>
</div>

<div class="actirise-info-text">
	<p><?php esc_html_e( 'When turned OFF, all Actirise ad placements will be disabled on this post.', 'actirise' ); ?></p>
</div>