<?php
/**
 * Writing Job Meta Box Template
 *
 * @package    Spawnster
 * @subpackage Spawnster/admin/partials
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}
?>

<table class="form-table">
	<tr>
		<th scope="row">
			<label for="specific_topic"><?php _e( 'Specific Topic', 'spawnster' ); ?></label>
		</th>
		<td>
			<input type="text" id="specific_topic" name="specificTopic" class="regular-text" value="<?php echo esc_attr( $specific_topic ); ?>" required>
			<p class="description"><?php _e( 'The main topic or keyword for content generation.', 'spawnster' ); ?></p>
		</td>
	</tr>
	
	<tr>
		<th scope="row">
			<label for="topic_category"><?php _e( 'Category', 'spawnster' ); ?></label>
		</th>
		<td>
			<?php
			// Get all categories from the 'post' post type
			$categories = get_categories( array(
				'taxonomy'   => 'category',
				'hide_empty' => false,
				'orderby'    => 'name',
				'order'      => 'ASC',
			) );
			?>
			<select id="topic_category" name="topicCategory">
				<option value=""><?php _e( 'Select a category', 'spawnster' ); ?></option>
				<?php foreach ( $categories as $category ) : ?>
					<option value="<?php echo esc_attr( $category->term_id ); ?>" <?php selected( $topic_category, $category->term_id ); ?>>
						<?php echo esc_html( $category->name ); ?>
					</option>
				<?php endforeach; ?>
			</select>
			<p class="description"><?php _e( 'Select the category for generated content.', 'spawnster' ); ?></p>
		</td>
	</tr>
	
	<tr>
		<th scope="row">
			<label for="word_count_goal"><?php _e( 'Word Count Goal', 'spawnster' ); ?></label>
		</th>
		<td>
			<input type="number" id="word_count_goal" name="wordCountGoal" class="small-text" value="<?php echo esc_attr( $word_count_goal ); ?>" min="100" max="5000" required>
			<p class="description"><?php _e( 'Target word count for generated content (100-5000 words).', 'spawnster' ); ?></p>
		</td>
	</tr>
	
	<tr>
		<th scope="row">
			<label for="past_articles"><?php _e( 'Research Articles', 'spawnster' ); ?></label>
		</th>
		<td>
			<input type="number" id="past_articles" name="pastArticles" class="small-text" value="<?php echo esc_attr( $past_articles ); ?>" min="1" max="20" required>
			<p class="description"><?php _e( 'Number of articles to research for content generation (1-20).', 'spawnster' ); ?></p>
		</td>
	</tr>
	
	<tr>
		<th scope="row">
			<label for="repeat"><?php _e( 'Repeat Generation', 'spawnster' ); ?></label>
		</th>
		<td>
			<label>
				<input type="checkbox" id="repeat" name="repeat" value="1" <?php checked( $repeat ); ?>>
				<?php _e( 'Enable automatic content generation on schedule', 'spawnster' ); ?>
			</label>
		</td>
	</tr>
	
	<tr class="repeat-options" style="display: <?php echo $repeat ? 'table-row' : 'none'; ?>;">
		<th scope="row">
			<label for="repeat_type"><?php _e( 'Schedule', 'spawnster' ); ?></label>
		</th>
		<td>
			<select id="repeat_type" name="repeatType">
				<option value="hourly" <?php selected( $repeat_type, 'hourly' ); ?>><?php _e( 'Hourly', 'spawnster' ); ?></option>
				<option value="daily" <?php selected( $repeat_type, 'daily' ); ?>><?php _e( 'Daily', 'spawnster' ); ?></option>
				<option value="weekly" <?php selected( $repeat_type, 'weekly' ); ?>><?php _e( 'Weekly', 'spawnster' ); ?></option>
				<option value="spawnster_monthly" <?php selected( $repeat_type, 'spawnster_monthly' ); ?>><?php _e( 'Monthly', 'spawnster' ); ?></option>
				<option value="spawnster_yearly" <?php selected( $repeat_type, 'spawnster_yearly' ); ?>><?php _e( 'Yearly', 'spawnster' ); ?></option>
			</select>
		</td>
	</tr>
	
	<tr class="repeat-options" style="display: <?php echo $repeat ? 'table-row' : 'none'; ?>;">
		<th scope="row">
			<label for="delay_publish"><?php _e( 'Delay (Hours)', 'spawnster' ); ?></label>
		</th>
		<td>
			<input type="number" id="delay_publish" name="delayPublish" class="small-text" value="<?php echo esc_attr( $delay_publish ); ?>" min="0" max="168">
			<p class="description"><?php _e( 'Delay before first generation (0-168 hours).', 'spawnster' ); ?></p>
		</td>
	</tr>
	
	<tr>
		<th scope="row">
			<label for="notify_admin"><?php _e( 'Notifications', 'spawnster' ); ?></label>
		</th>
		<td>
			<label>
				<input type="checkbox" id="notify_admin" name="notifyAdmin" value="1" <?php checked( $notify_admin ); ?>>
				<?php _e( 'Notify admin when content is generated', 'spawnster' ); ?>
			</label>
		</td>
	</tr>
</table>

<script>
jQuery(document).ready(function($) {
	// Show/hide repeat options based on checkbox
	$('#repeat').change(function() {
		if ($(this).is(':checked')) {
			$('.repeat-options').show();
		} else {
			$('.repeat-options').hide();
		}
	});
});
</script> 