<?php
/**
 * Settings tab - RSS Feeds.
 *
 * Variable: $options (Options instance)
 *
 * @package Relatedly
 * @since   2.0.0
 * @since   2.3.0 Rebuilt with native form rows.
 */

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
defined( 'ABSPATH' ) || exit;

use Relatedly\Premium\FeatureGate;

$is_premium    = FeatureGate::is_premium();
$max_rss_posts = FeatureGate::max_rss_posts();
?>
<div class="relatedly-settings-panel">
	<div class="relatedly-settings-panel-header">
		<h2 class="relatedly-settings-panel-title"><?php esc_html_e( 'RSS Feeds', 'relatedly' ); ?></h2>
		<p class="relatedly-settings-panel-desc"><?php esc_html_e( 'Add related posts to your RSS feed and label those links in your reports.', 'relatedly' ); ?></p>
	</div>

	<div class="relatedly-settings-panel-body">
		<table class="form-table relatedly-settings-table">
			<tbody>
				<tr>
					<th scope="row">
						<label class="relatedly-field-label" for="relatedly-rss-enabled"><?php esc_html_e( 'RSS Display', 'relatedly' ); ?></label>
						<p class="relatedly-field-hint"><?php esc_html_e( 'Show related posts inside each feed item.', 'relatedly' ); ?></p>
					</th>
					<td>
						<div class="relatedly-toggle-row">
							<div class="relatedly-toggle-switch">
								<input type="checkbox" name="rss_enabled" id="relatedly-rss-enabled" value="1" <?php checked( $options->get( 'rss_enabled', true ) ); ?>>
								<label for="relatedly-rss-enabled"></label>
							</div>
						</div>
					</td>
				</tr>

				<tr>
					<th scope="row">
						<label class="relatedly-field-label" for="relatedly-rss-interval"><?php esc_html_e( 'Inline Feed Interval', 'relatedly' ); ?></label>
						<p class="relatedly-field-hint"><?php esc_html_e( 'Place one related post after this many feed paragraphs.', 'relatedly' ); ?></p>
					</th>
					<td>
						<input type="number" name="rss_paragraph_interval" id="relatedly-rss-interval" class="relatedly-control" min="1" max="50" value="<?php echo esc_attr( $options->get( 'rss_paragraph_interval', 10 ) ); ?>">
					</td>
				</tr>

				<tr>
					<th scope="row">
						<label class="relatedly-field-label" for="relatedly-rss-end-enabled"><?php esc_html_e( 'End-of-Feed Posts', 'relatedly' ); ?></label>
						<p class="relatedly-field-hint"><?php esc_html_e( 'Append related posts at the end of each feed item.', 'relatedly' ); ?></p>
					</th>
					<td>
						<label class="relatedly-checkbox-item" for="relatedly-rss-end-enabled">
							<input type="checkbox" name="rss_end_content_enabled" id="relatedly-rss-end-enabled" value="1" <?php checked( $options->get( 'rss_end_content_enabled', true ) ); ?>>
							<?php esc_html_e( 'Append end-of-feed recommendations', 'relatedly' ); ?>
						</label>
					</td>
				</tr>

				<tr>
					<th scope="row">
						<label class="relatedly-field-label" for="relatedly-rss-count"><?php esc_html_e( 'Feed Post Count', 'relatedly' ); ?></label>
						<p class="relatedly-field-hint"><?php esc_html_e( 'Maximum recommendations appended to each feed item.', 'relatedly' ); ?></p>
					</th>
					<td>
						<input type="number" name="rss_end_content_max_posts" id="relatedly-rss-count" class="relatedly-control" min="1" max="<?php echo esc_attr( (string) $max_rss_posts ); ?>" value="<?php echo esc_attr( $options->get( 'rss_end_content_max_posts', 3 ) ); ?>">
						<?php if ( ! $is_premium ) : ?>
							<p class="relatedly-field-hint">
								<?php
								printf(
									/* translators: %d: free plan maximum RSS post count. */
									esc_html__( 'Free RSS limit: %d.', 'relatedly' ),
									(int) $max_rss_posts
								);
								?>
							</p>
						<?php endif; ?>
					</td>
				</tr>

				<tr>
					<th scope="row">
						<label class="relatedly-field-label" for="relatedly-utm-source"><?php esc_html_e( 'Source Label', 'relatedly' ); ?></label>
						<p class="relatedly-field-hint"><?php esc_html_e( 'A short report label for where the visitor came from.', 'relatedly' ); ?></p>
					</th>
					<td>
						<input type="text" name="utm_source" id="relatedly-utm-source" class="relatedly-control" value="<?php echo esc_attr( $options->get( 'utm_source', 'rss' ) ); ?>">
					</td>
				</tr>

				<tr>
					<th scope="row">
						<label class="relatedly-field-label" for="relatedly-utm-medium"><?php esc_html_e( 'Channel Label', 'relatedly' ); ?></label>
						<p class="relatedly-field-hint"><?php esc_html_e( 'A short report label for the kind of link.', 'relatedly' ); ?></p>
					</th>
					<td>
						<input type="text" name="utm_medium" id="relatedly-utm-medium" class="relatedly-control" value="<?php echo esc_attr( $options->get( 'utm_medium', 'related_posts' ) ); ?>">
					</td>
				</tr>

				<tr>
					<th scope="row">
						<label class="relatedly-field-label" for="relatedly-utm-campaign"><?php esc_html_e( 'Campaign Label', 'relatedly' ); ?></label>
						<p class="relatedly-field-hint"><?php esc_html_e( 'A short report label for this RSS related-post group.', 'relatedly' ); ?></p>
					</th>
					<td>
						<input type="text" name="utm_campaign" id="relatedly-utm-campaign" class="relatedly-control" value="<?php echo esc_attr( $options->get( 'utm_campaign', 'rss_related_posts' ) ); ?>">
					</td>
				</tr>
			</tbody>
		</table>
	</div>

	<div class="relatedly-save-bar">
		<?php submit_button( __( 'Save Changes', 'relatedly' ), 'primary', 'submit', false ); ?>
	</div>
</div>
