<?php

/**
 * Page: Add New Podcast.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

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

$appearance_settings = aiopod_get_option( 'aiopod_appearance_settings' );
?>
<div id="aiopod-post-new" class="aiopod aiopod-post-new">
	<div class="aiopod-container">
		<div class="aiopod-header">
			<h1><?php esc_html_e( 'Let\'s get started...', 'aio-podcast-studio' ); ?></h1>
			<p><?php esc_html_e( 'Start fresh by creating a new podcast, or import one from another platform to continue your journey.', 'aio-podcast-studio' ); ?></p>
		</div>

		<div class="aiopod-body">
			<div class="aiopod-card">
				<h3>
					<span class="dashicons dashicons-plus"></span>
					<?php esc_html_e( 'Create New Podcast', 'aio-podcast-studio' ); ?>
				</h3>

				<div class="aiopod-form-controls">
					<p class="description">
						<?php esc_html_e( 'Start uploading your episodes from scratch.', 'aio-podcast-studio' ); ?>
					</p>

					<div>
						<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=aiopod_podcasts' ) ); ?>" class="button button-primary button-hero"><?php esc_html_e( 'Start a New Podcast', 'aio-podcast-studio' ); ?></a>
					</div>
				</div>
			</div>

			<div class="aiopod-card">
				<h3>
					<span class="dashicons dashicons-rss"></span>
					<?php esc_html_e( 'Import Podcast from RSS Feed', 'aio-podcast-studio' ); ?>
				</h3>

				<div class="aiopod-form-controls">
					<p class="description">
						<?php esc_html_e( 'Have an existing show? Import all episodes using your RSS feed.', 'aio-podcast-studio' ); ?>
					</p>
					
					<!-- Field: RSS Feed URL -->
					<div id="aiopod-form-control-rss_feed_url" class="aiopod-form-control">
						<label for="aiopod-field-rss_feed_url" class="aiopod-form-label">
							<?php esc_html_e( 'RSS Feed URL', 'aio-podcast-studio' ); ?>
						</label>

						<div class="aiopod-form-field">
							<input type="text" name="rss_feed_url" id="aiopod-field-rss_feed_url" class="widefat" placeholder="<?php esc_attr_e( 'Enter your RSS feed URL', 'aio-podcast-studio' ); ?>" />
						</div>

						<p class="description">
							<?php
							printf(
								/* translators: %1$s: opening anchor tag, %2$s: closing anchor tag */
								esc_html__( 'Don\'t have a feed handy? %1$sTry a sample feed%2$s to see how the import works.', 'aio-podcast-studio' ),
								'<a href="#" id="aiopod-link-sample_feed_url" data-feed-url="' . esc_attr( apply_filters( 'aiopod_sample_feed_url', 'https://feeds.megaphone.fm/NATIONALAERONAUTICSANDSPACEADMINISTRATION1776343825' ) ) . '">',
								'</a>'
							);
							?>
						</p>
					</div>

					<!-- Field: Set Featured Image? -->
					<?php if ( ! empty( $appearance_settings['enable_featured_images'] ) && ! empty( $appearance_settings['download_external_images'] ) ) : ?>
						<div id="aiopod-form-control-set_featured_image" class="aiopod-form-control">
							<label for="aiopod-field-set_featured_image" class="aiopod-form-label">
								<?php esc_html_e( 'Set Featured Image?', 'aio-podcast-studio' ); ?>
							</label>
							
							<label class="aiopod-form-field">
								<input type="checkbox" name="set_featured_image" id="aiopod-field-set_featured_image" value="1" />
								<?php esc_html_e( 'Enable to automatically download and set featured images from the RSS feed.', 'aio-podcast-studio' ); ?>
							</label>

							<p class="description">
								<?php esc_html_e( 'Note: This may slow down the import process for podcasts with many episodes or large images.', 'aio-podcast-studio' ); ?>
							</p>
						</div>
					<?php endif; ?>
					
					<!-- Field: Auto-update Episodes? -->
					<div id="aiopod-form-control-auto_update_episodes" class="aiopod-form-control">
						<label for="aiopod-field-auto_update_episodes" class="aiopod-form-label">
							<?php esc_html_e( 'Auto-update Episodes?', 'aio-podcast-studio' ); ?>
						</label>
						
						<label class="aiopod-form-field">
							<input type="checkbox" name="auto_update_episodes" id="aiopod-field-auto_update_episodes" value="1" />
							<?php esc_html_e( 'Enable to automatically fetch new episodes from the imported feed.', 'aio-podcast-studio' ); ?>
						</label>						
					</div>

					<!-- Field: Auto-update Frequency -->
					<div id="aiopod-form-control-auto_update_frequency" class="aiopod-form-control" style="display: none;">
						<label for="aiopod-field-auto_update_frequency" class="aiopod-form-label">
							<?php esc_html_e( 'Auto-update Frequency', 'aio-podcast-studio' ); ?>
						</label>
						
						<div class="aiopod-form-field">
							<select name="auto_update_frequency" id="aiopod-field-auto_update_frequency" class="widefat">
								<?php
								$options = array(
									'0'       => __( 'Only Once', 'aio-podcast-studio' ),
									'3600'    => __( 'Every 1 Hour', 'aio-podcast-studio' ),
									'86400'   => __( 'Every 1 Day', 'aio-podcast-studio' ),
									'604800'  => __( 'Every 1 Week', 'aio-podcast-studio' ),
									'2419200' => __( 'Every 1 Month', 'aio-podcast-studio' )
								);

								foreach ( $options as $key => $label ) {
									printf( 
										'<option value="%s">%s</option>', 
										esc_attr( $key ), 
										esc_html( $label )
									);
								}
								?>
							</select>
						</div>
						
						<p class="description">
							<?php esc_html_e( 'Choose how often the imported feed should be checked for new episodes.', 'aio-podcast-studio' ); ?>
						</p>
					</div>
					
					<!-- Button: Import My Podcast -->
					<div id="aiopod-form-control-import_podcast" class="aiopod-form-control">
						<div class="aiopod-form-field">
							<button type="button" id="aiopod-button-import_podcast" class="button button-primary button-hero">
								<?php esc_html_e( 'Import My Podcast', 'aio-podcast-studio' ); ?>
							</button>
						</div>
						<div class="aiopod-form-status" aria-live="polite" role="status"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
