<?php
/**
 * Livada SEO — Robots.txt Settings View
 *
 * @package Livada_SEO
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$robots_txt = Livada_SEO_Loader::get_setting( 'robots_txt', "User-agent: *\nAllow: /\nSitemap: %siteurl%/sitemap.xml" );
?>
<div class="wrap livada-seo-wrap has-ls-hero">
<?php include LIVADA_SEO_PATH . 'includes/admin/views/_partials/header.php'; ?>
	<h1><?php esc_html_e( 'Robots.txt', 'livada-seo' ); ?></h1>

	<?php if ( isset( $_GET['updated'] ) ) : // phpcs:ignore ?>
		<div class="notice notice-success is-dismissible"><p><?php esc_html_e( 'Settings saved.', 'livada-seo' ); ?></p></div>
	<?php endif; ?>

	<p class="description">
		<?php esc_html_e( 'This content is served at ', 'livada-seo' ); ?>
		<a href="<?php echo esc_url( home_url( '/robots.txt' ) ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( home_url( '/robots.txt' ) ); ?></a>.
	</p>

	<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
		<?php wp_nonce_field( 'livada_seo_save_robots' ); ?>
		<input type="hidden" name="action" value="livada_seo_save_robots">

		<table class="form-table" role="presentation">
			<tbody>
				<tr>
					<th scope="row">
						<label for="robots_txt"><?php esc_html_e( 'Robots.txt Content', 'livada-seo' ); ?></label>
					</th>
					<td>
						<textarea
							id="robots_txt"
							name="livada_seo[robots_txt]"
							class="large-text code"
							rows="12"
						><?php echo esc_textarea( $robots_txt ); ?></textarea>
						<p class="description">
							<?php esc_html_e( 'Use %siteurl% as a placeholder for your site\'s home URL — it will be replaced at serve time.', 'livada-seo' ); ?>
						</p>
					</td>
				</tr>
			</tbody>
		</table>

		<?php submit_button( __( 'Save Settings', 'livada-seo' ) ); ?>
	</form>
</div>
