<?php
/**
 * Meta box template.
 *
 * @var \WP_Post $post
 * @var bool     $enabled
 * @var string   $date_value        "Y-m-d H:i" formátum (Flatpickr)
 * @var string   $expiration_action
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div class="spe-meta-box">

	<label class="spe-toggle-label">
		<span class="spe-toggle-switch">
			<input
				type="checkbox"
				id="spe_enabled"
				name="spe_enabled"
				value="1"
				<?php checked( $enabled ); ?>
			>
			<span class="spe-toggle-slider"></span>
		</span>
		<span class="spe-toggle-text">
			<?php esc_html_e( 'Enable expiration', 'monkeydesign-content-expiry' ); ?>
		</span>
	</label>

	<div id="spe-fields" class="spe-fields" <?php echo $enabled ? '' : 'style="display:none"'; ?>>

		<div class="spe-field-row">
			<label class="spe-label" for="spe_expiration_date">
				<?php esc_html_e( 'Expiration date & time', 'monkeydesign-content-expiry' ); ?>
			</label>
			<div class="spe-input-wrap spe-input-wrap--icon">
				<input
					type="text"
					id="spe_expiration_date"
					name="spe_expiration_date"
					class="spe-input spe-datetime-input"
					value="<?php echo esc_attr( $date_value ); ?>"
					placeholder="<?php esc_attr_e( 'Select date and time…', 'monkeydesign-content-expiry' ); ?>"
					readonly
				>
				<span class="spe-input-icon" aria-hidden="true">
					<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
						<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
						<line x1="16" y1="2" x2="16" y2="6"></line>
						<line x1="8" y1="2" x2="8" y2="6"></line>
						<line x1="3" y1="10" x2="21" y2="10"></line>
					</svg>
				</span>
			</div>
		</div>

		<div class="spe-field-row">
			<label class="spe-label" for="spe_expiration_action">
				<?php esc_html_e( 'On expiration', 'monkeydesign-content-expiry' ); ?>
			</label>
			<div class="spe-select-wrap">
				<select id="spe_expiration_action" name="spe_expiration_action" class="spe-select">
					<option value="draft"   <?php selected( $expiration_action, 'draft' ); ?>>
						<?php esc_html_e( 'Change to Draft', 'monkeydesign-content-expiry' ); ?>
					</option>
					<option value="private" <?php selected( $expiration_action, 'private' ); ?>>
						<?php esc_html_e( 'Make Private', 'monkeydesign-content-expiry' ); ?>
					</option>
					<option value="trash"   <?php selected( $expiration_action, 'trash' ); ?>>
						<?php esc_html_e( 'Move to Trash', 'monkeydesign-content-expiry' ); ?>
					</option>
					<option value="delete"  <?php selected( $expiration_action, 'delete' ); ?>>
						<?php esc_html_e( 'Delete permanently', 'monkeydesign-content-expiry' ); ?>
					</option>
					<?php if ( $has_categories ) : ?>
					<option value="category" <?php selected( $expiration_action, 'category' ); ?>>
						<?php esc_html_e( 'Change category', 'monkeydesign-content-expiry' ); ?>
					</option>
					<?php endif; ?>
					<option value="title" <?php selected( $expiration_action, 'title' ); ?>>
						<?php esc_html_e( 'Change title', 'monkeydesign-content-expiry' ); ?>
					</option>
					<optgroup label="✦ PRO">
						<?php if ( defined( 'MDCE_PRO_VERSION' ) ) : ?>
							<?php do_action( 'mdce_expiration_action_options', $expiration_action ); ?>
						<?php else : ?>
							<option value="" disabled><?php esc_html_e( 'Redirect to URL', 'monkeydesign-content-expiry' ); ?></option>
							<option value="" disabled><?php esc_html_e( 'Replace content', 'monkeydesign-content-expiry' ); ?></option>
						<?php endif; ?>
					</optgroup>
				</select>
				<span class="spe-select-arrow" aria-hidden="true">
					<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
						<polyline points="6 9 12 15 18 9"></polyline>
					</svg>
				</span>
			</div>
		</div>

		<?php if ( $has_categories ) : ?>
		<div id="spe-category-wrap" class="spe-field-row"<?php echo $expiration_action !== 'category' ? ' style="display:none"' : ''; ?>>
			<label class="spe-label"><?php esc_html_e( 'Replace with category', 'monkeydesign-content-expiry' ); ?></label>
			<?php
			wp_dropdown_categories( [
				'name'             => 'spe_expiry_category_ids[]',
				'id'               => 'spe-expiry-category',
				'class'            => 'spe-select',
				'show_option_none' => __( '— Select category —', 'monkeydesign-content-expiry' ),
				'option_none_value'=> '',
				'selected'         => ! empty( $expiry_category_ids ) ? reset( $expiry_category_ids ) : '',
				'hide_empty'       => false,
			] );
			?>
		</div>
		<?php endif; ?>

		<div id="spe-title-wrap" class="spe-field-row"<?php echo $expiration_action !== 'title' ? ' style="display:none"' : ''; ?>>
			<label class="spe-label" for="spe-expiry-new-title">
				<?php esc_html_e( 'New title', 'monkeydesign-content-expiry' ); ?>
			</label>
			<input
				type="text"
				id="spe-expiry-new-title"
				name="spe_expiry_new_title"
				value="<?php echo esc_attr( $expiry_new_title ); ?>"
				class="spe-input widefat"
				placeholder="<?php esc_attr_e( 'Title after expiry…', 'monkeydesign-content-expiry' ); ?>"
			>
		</div>

		<?php do_action( 'mdce_meta_box_fields', $post, $expiration_action ); ?>

	</div><!-- .spe-fields -->

</div><!-- .spe-meta-box -->
