<?php
/**
 * Admin settings template.
 *
 * @package CertaCart_EU_Product_Readiness
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$option = \CertaCart\EU_Product_Readiness\Settings::OPTION; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local value.
$notice_image = ! empty( $settings['notice_attachment_id'] ) ? wp_get_attachment_image_url( (int) $settings['notice_attachment_id'], 'medium' ) : ''; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local value.
?>
<div class="wrap ccpr-wrap" id="ccpr-settings-page">
	<?php $ccpr_current_page = 'settings'; require CCPR_PATH . 'templates/admin-navigation.php'; ?>
	<main class="ccpr-main">
	<div class="ccpr-page-heading"><div><p class="ccpr-eyebrow"><?php esc_html_e( 'Smart defaults first', 'certacart-eu-product-readiness' ); ?></p><h1><?php esc_html_e( 'Settings', 'certacart-eu-product-readiness' ); ?></h1><p><?php esc_html_e( 'CertaCart works out of the box. Change these only when your store needs something different.', 'certacart-eu-product-readiness' ); ?></p></div></div>
	<form action="options.php" method="post">
		<?php settings_fields( 'ccpr_settings_group' ); ?>
		<div class="ccpr-settings-section">
			<h2><?php esc_html_e( 'Store defaults', 'certacart-eu-product-readiness' ); ?></h2>
			<table class="form-table" role="presentation">
				<tr><th scope="row"><label for="ccpr-default-targets-eu"><?php esc_html_e( 'Products offered to EU consumers', 'certacart-eu-product-readiness' ); ?></label></th><td>
					<select id="ccpr-default-targets-eu" name="<?php echo esc_attr( $option ); ?>[default_targets_eu]"><option value="review" <?php selected( $settings['default_targets_eu'], 'review' ); ?>><?php esc_html_e( 'Not configured yet', 'certacart-eu-product-readiness' ); ?></option><option value="yes" <?php selected( $settings['default_targets_eu'], 'yes' ); ?>><?php esc_html_e( 'Yes by default', 'certacart-eu-product-readiness' ); ?></option><option value="no" <?php selected( $settings['default_targets_eu'], 'no' ); ?>><?php esc_html_e( 'No by default', 'certacart-eu-product-readiness' ); ?></option></select>
					<p class="description"><?php esc_html_e( 'Unconfigured products are not scored, and CertaCart information is not shown on their product pages. Individual products can override this setting.', 'certacart-eu-product-readiness' ); ?></p>
				</td></tr>
				<tr><th scope="row"><label for="ccpr-default-manufacturer-eu"><?php esc_html_e( 'Manufacturer established in the EU', 'certacart-eu-product-readiness' ); ?></label></th><td>
					<select id="ccpr-default-manufacturer-eu" name="<?php echo esc_attr( $option ); ?>[default_manufacturer_in_eu]"><option value="unknown" <?php selected( $settings['default_manufacturer_in_eu'], 'unknown' ); ?>><?php esc_html_e( 'Not confirmed', 'certacart-eu-product-readiness' ); ?></option><option value="yes" <?php selected( $settings['default_manufacturer_in_eu'], 'yes' ); ?>><?php esc_html_e( 'Yes', 'certacart-eu-product-readiness' ); ?></option><option value="no" <?php selected( $settings['default_manufacturer_in_eu'], 'no' ); ?>><?php esc_html_e( 'No', 'certacart-eu-product-readiness' ); ?></option></select>
				</td></tr>
				<tr><th scope="row"><?php esc_html_e( 'Show product information', 'certacart-eu-product-readiness' ); ?></th><td><label><input type="checkbox" name="<?php echo esc_attr( $option ); ?>[display_product_information]" value="yes" <?php checked( $settings['display_product_information'], 'yes' ); ?>> <?php esc_html_e( 'Display configured information on product pages by default', 'certacart-eu-product-readiness' ); ?></label></td></tr>
				<tr><th scope="row"><label for="ccpr-position"><?php esc_html_e( 'Display position', 'certacart-eu-product-readiness' ); ?></label></th><td><select id="ccpr-position" name="<?php echo esc_attr( $option ); ?>[display_position]"><option value="after_summary" <?php selected( $settings['display_position'], 'after_summary' ); ?>><?php esc_html_e( 'After product summary', 'certacart-eu-product-readiness' ); ?></option><option value="before_add_to_cart" <?php selected( $settings['display_position'], 'before_add_to_cart' ); ?>><?php esc_html_e( 'Before add-to-cart form', 'certacart-eu-product-readiness' ); ?></option><option value="after_meta" <?php selected( $settings['display_position'], 'after_meta' ); ?>><?php esc_html_e( 'After product metadata', 'certacart-eu-product-readiness' ); ?></option><option value="manual" <?php selected( $settings['display_position'], 'manual' ); ?>><?php esc_html_e( 'Manual placement only (block or shortcode)', 'certacart-eu-product-readiness' ); ?></option></select><p class="description"><?php esc_html_e( 'Use manual placement to avoid duplicate output when a page builder, shortcode, or block controls the location.', 'certacart-eu-product-readiness' ); ?></p></td></tr>
				<tr><th scope="row"><label for="ccpr-heading"><?php esc_html_e( 'Section heading', 'certacart-eu-product-readiness' ); ?></label></th><td><input class="regular-text" id="ccpr-heading" name="<?php echo esc_attr( $option ); ?>[section_heading]" value="<?php echo esc_attr( $settings['section_heading'] ); ?>"></td></tr>
			</table>
		</div>

		<details class="ccpr-settings-disclosure">
			<summary><span><strong><?php esc_html_e( 'Storefront guarantee notice', 'certacart-eu-product-readiness' ); ?></strong><small><?php esc_html_e( 'Artwork and placement', 'certacart-eu-product-readiness' ); ?></small></span></summary>
		<div class="ccpr-settings-section">
			<p><?php esc_html_e( 'Use the official artwork for your storefront language.', 'certacart-eu-product-readiness' ); ?></p>
			<table class="form-table" role="presentation">
				<tr><th scope="row"><label for="ccpr-notice-scope"><?php esc_html_e( 'Use this notice' , 'certacart-eu-product-readiness' ); ?></label></th><td><select id="ccpr-notice-scope" name="<?php echo esc_attr( $option ); ?>[notice_scope]"><option value="review" <?php selected( $settings['notice_scope'], 'review' ); ?>><?php esc_html_e( 'Decide later', 'certacart-eu-product-readiness' ); ?></option><option value="configured" <?php selected( $settings['notice_scope'], 'configured' ); ?>><?php esc_html_e( 'Yes, set it up here', 'certacart-eu-product-readiness' ); ?></option><option value="not_applicable" <?php selected( $settings['notice_scope'], 'not_applicable' ); ?>><?php esc_html_e( 'Not needed for this store', 'certacart-eu-product-readiness' ); ?></option></select></td></tr>
				<tr><th scope="row"><?php esc_html_e( 'Enable placement', 'certacart-eu-product-readiness' ); ?></th><td><label><input type="checkbox" name="<?php echo esc_attr( $option ); ?>[notice_enabled]" value="yes" <?php checked( $settings['notice_enabled'], 'yes' ); ?>> <?php esc_html_e( 'Display the selected notice image with the product information section', 'certacart-eu-product-readiness' ); ?></label></td></tr>
				<tr><th scope="row"><?php esc_html_e( 'Notice artwork', 'certacart-eu-product-readiness' ); ?></th><td>
					<input type="hidden" id="ccpr-notice-attachment-id" name="<?php echo esc_attr( $option ); ?>[notice_attachment_id]" value="<?php echo esc_attr( (string) $settings['notice_attachment_id'] ); ?>">
					<div id="ccpr-notice-preview"><?php if ( $notice_image ) : ?><img src="<?php echo esc_url( $notice_image ); ?>" alt=""><?php endif; ?></div>
					<button type="button" class="button" id="ccpr-select-notice"><?php esc_html_e( 'Select image', 'certacart-eu-product-readiness' ); ?></button> <button type="button" class="button" id="ccpr-clear-notice"><?php esc_html_e( 'Clear', 'certacart-eu-product-readiness' ); ?></button>
					<p class="description"><?php esc_html_e( 'Upload the official PNG, JPEG, or WebP artwork.', 'certacart-eu-product-readiness' ); ?></p>
				</td></tr>
				<tr><th scope="row"><label for="ccpr-notice-alt"><?php esc_html_e( 'Alternative text', 'certacart-eu-product-readiness' ); ?></label></th><td><input class="regular-text" id="ccpr-notice-alt" name="<?php echo esc_attr( $option ); ?>[notice_alt_text]" value="<?php echo esc_attr( $settings['notice_alt_text'] ); ?>"></td></tr>
				<tr><th scope="row"><label for="ccpr-notice-link"><?php esc_html_e( 'Optional official-information link', 'certacart-eu-product-readiness' ); ?></label></th><td><input type="url" class="regular-text" id="ccpr-notice-link" name="<?php echo esc_attr( $option ); ?>[notice_link_url]" value="<?php echo esc_attr( $settings['notice_link_url'] ); ?>"></td></tr>
			</table>
			<p><a href="https://commission.europa.eu/publications/harmonised-notice-legal-guarantee-conformity-and-harmonised-label-commercial-guarantee-durability_en" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Open the European Commission’s official notice and label page', 'certacart-eu-product-readiness' ); ?></a></p>
		</div>
		</details>

		<details class="ccpr-settings-disclosure">
			<summary><span><strong><?php esc_html_e( 'Advanced', 'certacart-eu-product-readiness' ); ?></strong><small><?php esc_html_e( 'Scanner, retention, and uninstall options', 'certacart-eu-product-readiness' ); ?></small></span></summary>
		<div class="ccpr-settings-section">
			<table class="form-table" role="presentation">
				<tr><th scope="row"><label for="ccpr-batch-size"><?php esc_html_e( 'Products per batch', 'certacart-eu-product-readiness' ); ?></label></th><td><input type="number" min="50" max="2000" id="ccpr-batch-size" name="<?php echo esc_attr( $option ); ?>[batch_size]" value="<?php echo esc_attr( (string) $settings['batch_size'] ); ?>"><p class="description"><?php esc_html_e( 'Lower this value only if your host runs out of memory during a scan.', 'certacart-eu-product-readiness' ); ?></p></td></tr>
				<tr><th scope="row"><label for="ccpr-retention"><?php esc_html_e( 'Reports to retain', 'certacart-eu-product-readiness' ); ?></label></th><td><input type="number" min="1" max="50" id="ccpr-retention" name="<?php echo esc_attr( $option ); ?>[retention_scans]" value="<?php echo esc_attr( (string) $settings['retention_scans'] ); ?>"></td></tr>
				<tr><th scope="row"><?php esc_html_e( 'Uninstall behavior', 'certacart-eu-product-readiness' ); ?></th><td><label><input type="checkbox" name="<?php echo esc_attr( $option ); ?>[delete_data_on_uninstall]" value="yes" <?php checked( $settings['delete_data_on_uninstall'], 'yes' ); ?>> <?php esc_html_e( 'Permanently delete CertaCart settings, scan tables, and product metadata when the plugin is deleted', 'certacart-eu-product-readiness' ); ?></label></td></tr>
			</table>
		</div>
		</details>
		<details class="ccpr-settings-disclosure">
			<summary><span><strong><?php esc_html_e( 'About CertaCart', 'certacart-eu-product-readiness' ); ?></strong><small><?php esc_html_e( 'Supported checks and product scope', 'certacart-eu-product-readiness' ); ?></small></span></summary>
			<div class="ccpr-settings-section"><p><?php esc_html_e( 'CertaCart checks product information and storefront settings against its supported EU product information rules. It is not a legal certification.', 'certacart-eu-product-readiness' ); ?></p></div>
		</details>
		<?php submit_button(); ?>
	</form>
	</main>
</div>
