<?php

/**
 * Accordion: RSS Feed.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

// Exit if accessed directly
if ( ! defined( 'WPINC' ) ) {
	die;
}

$author_name      = isset( $post_meta['author_name'] ) ? $post_meta['author_name'][0] : '%%author_name%%';
$author_email     = isset( $post_meta['author_email'] ) ? $post_meta['author_email'][0] : '%%author_email%%';
$website_url      = isset( $post_meta['website_url'] ) ? $post_meta['website_url'][0] : '%%podcast_url%%';
$copyright_text   = isset( $post_meta['copyright_text'] ) ? $post_meta['copyright_text'][0] : '';
$podcast_language = isset( $post_meta['podcast_language'] ) ? $post_meta['podcast_language'][0] : '';
$podcast_type     = isset( $post_meta['podcast_type'] ) ? $post_meta['podcast_type'][0] : '';
$is_completed     = isset( $post_meta['is_completed'] ) ? $post_meta['is_completed'][0] : 0;
?>
<div class="aiopod-form-controls">
	<div class="aiopod-notice aiopod-notice-info">
		<?php esc_html_e( 'These settings are included in your podcast\'s RSS feed and affect how your show appears in directories like Apple Podcasts and Spotify.', 'aio-podcast-studio' ); ?>
	</div>

	<div class="aiopod-form-grid">
		<!-- Field: Author Name -->
		<div id="aiopod-form-control-author_name" class="aiopod-form-control">
			<label for="aiopod-field-author_name" class="aiopod-form-label">
				<?php esc_html_e( 'Author Name', 'aio-podcast-studio' ); ?>
			</label>

			<div class="aiopod-form-field">
				<input type="text" name="author_name" id="aiopod-field-author_name" class="widefat" placeholder="John Doe" value="<?php echo esc_attr( $author_name ); ?>" />
			</div>

			<p class="description">
				<?php echo wp_kses( __( 'Used in your RSS feed only. <code>%%author_name%%</code> is replaced with the display name of the WordPress user who created this podcast.', 'aio-podcast-studio' ), array( 'code' => array() ) ); ?>
			</p>
		</div>

		<!-- Field: Author Email -->
		<div id="aiopod-form-control-author_email" class="aiopod-form-control">
			<label for="aiopod-field-author_email" class="aiopod-form-label">
				<?php esc_html_e( 'Author Email', 'aio-podcast-studio' ); ?>
			</label>

			<div class="aiopod-form-field">
				<input type="text" name="author_email" id="aiopod-field-author_email" class="widefat" placeholder="john.doe@example.com" value="<?php echo esc_attr( $author_email ); ?>" />
			</div>

			<p class="description">
				<?php echo wp_kses( __( 'Used in your RSS feed only. <code>%%author_email%%</code> is replaced with the email address of the WordPress user who created this podcast.', 'aio-podcast-studio' ), array( 'code' => array() ) ); ?>
			</p>
		</div>

		<!-- Field: Website URL -->
		<div id="aiopod-form-control-website_url" class="aiopod-form-control">
			<label for="aiopod-field-website_url" class="aiopod-form-label">
				<?php esc_html_e( 'Website URL', 'aio-podcast-studio' ); ?>
			</label>

			<div class="aiopod-form-field">
				<input type="text" name="website_url" id="aiopod-field-website_url" class="widefat" placeholder="https://example.com/my-podcast/" value="<?php echo esc_attr( $website_url ); ?>" />
			</div>

			<p class="description">
				<?php echo wp_kses( __( 'Used in your RSS feed only. <code>%%podcast_url%%</code> is replaced with the URL of the current podcast.', 'aio-podcast-studio' ), array( 'code' => array() ) ); ?>
			</p>
		</div>

		<!-- Field: Copyright Text -->
		<div id="aiopod-form-control-copyright_text" class="aiopod-form-control">
			<label for="aiopod-field-copyright_text" class="aiopod-form-label">
				<?php esc_html_e( 'Copyright Text', 'aio-podcast-studio' ); ?>
			</label>

			<div class="aiopod-form-field">
				<input type="text" name="copyright_text" id="aiopod-field-copyright_text" class="widefat" placeholder="© 2025 John Doe" value="<?php echo esc_attr( $copyright_text ); ?>" />
			</div>

			<p class="description">
				<?php esc_html_e( 'Used in your RSS feed only. Your copyright notice, typically the year and name (e.g., © 2025 John Doe).', 'aio-podcast-studio' ); ?>
			</p>
		</div>

		<!-- Field: Podcast Language -->
		<div id="aiopod-form-control-podcast_language" class="aiopod-form-control">
			<label for="aiopod-field-podcast_language" class="aiopod-form-label">
				<?php esc_html_e( 'Podcast Language', 'aio-podcast-studio' ); ?>
			</label>

			<div class="aiopod-form-field">
				<select name="podcast_language" id="aiopod-field-podcast_language" class="widefat">
					<?php
					require_once AIOPOD_PLUGIN_DIR . 'includes/podcast-languages.php';

					printf(
						'<option value="">— %s —</option>',
						esc_html__( 'Site default', 'aio-podcast-studio' )
					);

					foreach ( $aiopod_languages as $language_code => $language_text ) {
						printf(
							'<option value="%s"%s>%s</option>',
							esc_attr( $language_code ),
							selected( $language_code, $podcast_language, false ),
							esc_html( $language_text )
						);
					}
					?>
				</select>
			</div>

			<p class="description">
				<?php esc_html_e( 'The primary language spoken in your episodes. Defaults to your site language if not set. Included in your RSS feed to help directories surface your show to the right audiences.', 'aio-podcast-studio' ); ?>
			</p>
		</div>

		<!-- Field: Podcast Type -->
		<div id="aiopod-form-control-podcast_type" class="aiopod-form-control">
			<label for="aiopod-field-podcast_type" class="aiopod-form-label">
				<?php esc_html_e( 'Podcast Type', 'aio-podcast-studio' ); ?>
			</label>

			<div class="aiopod-form-field">
				<select name="podcast_type" id="aiopod-field-podcast_type" class="widefat">
					<?php
					$options = array(
						''           => '— ' . __( 'Select an option', 'aio-podcast-studio' ) . ' —',
						'episodic'   => __( 'Episodic', 'aio-podcast-studio' ),
						'serialized' => __( 'Serial', 'aio-podcast-studio' ),
					);

					foreach ( $options as $key => $label ) {
						printf(
							'<option value="%s"%s>%s</option>',
							esc_attr( $key ),
							selected( $key, $podcast_type, false ),
							esc_html( $label )
						);
					}
					?>
				</select>
			</div>

			<p class="description">
				<?php esc_html_e( 'Included in your RSS feed. Choose "Episodic" for standalone episodes or "Serial" for a season-based narrative. This affects how podcast directories like Apple Podcasts present your show.', 'aio-podcast-studio' ); ?>
			</p>
		</div>
	</div>

	<!-- Field: Mark as Complete -->
	<div id="aiopod-form-control-is_completed" class="aiopod-form-control">
		<label for="aiopod-field-is_completed" class="aiopod-form-label">
			<?php esc_html_e( 'Mark as Complete', 'aio-podcast-studio' ); ?>
		</label>

		<label class="aiopod-form-field">
			<input type="checkbox" name="is_completed" id="aiopod-field-is_completed" value="1" <?php checked( $is_completed, 1 ); ?> />
			<?php esc_html_e( 'Check this if your show has ended and no new episodes will be published. This signals to podcast directories (via your RSS feed) to stop checking for new episodes.', 'aio-podcast-studio' ); ?>
		</label>
	</div>
</div>
