<?php
// phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment

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

global $R34ICSPro;

if (r34ics_is_block_editor()) {
	?>
	<div class="wp-block components-placeholder r34icspro-block-shortcode-wrapper" style="overflow: clip;">
		<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif; font-size: 1rem; text-align: center; width: 100%;">
			<div style="display: block; height: 3rem; width: 3rem; margin: 0 auto;">
				<?php
				// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				echo $R34ICSPro->icon_svg;
				?>
			</div>
			<?php
			if (empty($attr['calendar_id'])) {
				?>
				<p>
					<?php
					printf(esc_html__('Select a calendar using the %1$sSaved Calendar%2$s dropdown menu in the Block Settings sidebar.', 'ics-calendar-pro'), '<strong style="font-weight: 700;">', '</strong>');
					?>
					<br />
					<small><?php esc_html_e('Note: The calendar will display on the front end page, but does not render here in the Block Editor.', 'ics-calendar-pro'); ?></small>
				</p>
				<?php
			}
			else {
				?>
				<h2 style="font-size: 150%; font-weight: 700; margin: 0;"><?php echo wp_kses_post(get_the_title($attr['calendar_id'])); ?></h2>
				<p style="margin: 0;">
					<small>
						<?php
						esc_html_e('View:', 'ics-calendar-pro');
						echo ' ';
						// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
						esc_html_e(r34icspro_convert_view_name(get_post_meta($attr['calendar_id'], 'view', true)), 'ics-calendar-pro');
						echo ' (ID: ' . intval($attr['calendar_id']) . ')';
						?>
					</small>
				</p>
				<p>
					<?php
					printf(esc_html__('You can change the selected calendar using the %1$sSaved Calendar%2$s dropdown menu in the Block Settings sidebar.', 'ics-calendar-pro'), '<strong style="font-weight: 700;">', '</strong>');
					?>
					<br />
					<small><?php esc_html_e('Note: The calendar will display on the front end page, but does not render here in the Block Editor.', 'ics-calendar-pro'); ?></small>
				</p>
				<?php
			}
			?>
		</div>
	</div>
	<?php
	return;
}

if (!empty($attr['calendar_id'])) {

	echo '<div ' . wp_kses_post(get_block_wrapper_attributes()) . '>';
	echo do_shortcode('[ics_calendar id="' . intval($attr['calendar_id']). '"]');
	echo '</div>';

}
