<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

// Don't load directly
if (!defined('ABSPATH')) { exit; }

$saved_calendars = get_posts(array('post_type' => 'r34icspro_calendar', 'post_status' => 'publish'));

if (empty($saved_calendars)) {
	?>
	<p><?php esc_html_e('You have no saved calendars.', 'ics-calendar-pro'); ?></p>
	<?php
}
else {
	?>
	<p class="field-block saved_calendar">
		<label for="insert_r34ics_id"><strong><?php esc_html_e('Load Saved Calendar:', 'ics-calendar-pro'); ?></strong></label><br />
		<select id="insert_r34ics_id" name="insert_r34ics_id">
			<option value=""><?php esc_html_e('Select one...', 'ics-calendar-pro'); ?></option>
			<?php
			foreach ((array)$saved_calendars as $saved_calendar) {
				?>
				<option value="<?php echo intval($saved_calendar->ID); ?>"><?php echo wp_kses_post(get_the_title($saved_calendar)); ?></option>
				<?php
			}
			?>
		</select>
	</p>
	<?php
}
?>

<p><a href="<?php echo esc_url(admin_url('post-new.php?post_type=r34icspro_calendar')); ?>"><?php esc_html_e('Create a new calendar...', 'ics-calendar-pro'); ?></a></p>
