<?php
/**
 * Template: Shortcodes Reference
 *
 * Renders a static reference list of all available Biscotti shortcodes.
 * No API call needed — all content is bundled in the plugin.
 *
 * @var array $data Unused for this static page.
 * @package Biscotti_CMP
 */

defined( 'ABSPATH' ) || exit;

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template is included inside Biscotti_Admin::render_dynamic_page(); these are function-scoped locals, not globals.

$shortcodes = array(
	array(
		'tag'         => '[biscotti_cookies]',
		'description' => __( 'Displays a table of all cookies used on your website, grouped by category. Ideal for embedding in your Privacy Policy or Cookie Policy page.', 'biscotti-cmp' ),
		'attributes'  => array(
			'category'      => __( 'Filter by category: "all", "essential", "functional", "analytics", or "marketing". Default: "all".', 'biscotti-cmp' ),
			'show_duration' => __( 'Show cookie duration column. "true" or "false". Default: "true".', 'biscotti-cmp' ),
			'show_provider' => __( 'Show provider column. "true" or "false". Default: "true".', 'biscotti-cmp' ),
			'lang'          => __( 'Override language (2-letter code, e.g. "de", "en"). Default: auto-detected.', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti_cookies category="all" show_duration="true"]',
	),
	array(
		'tag'         => '[biscotti_consent_link]',
		'description' => __( 'Renders a link that reopens the consent banner when clicked. Use this to let visitors change their cookie preferences.', 'biscotti-cmp' ),
		'attributes'  => array(
			'text'  => __( 'Link text. Default: "Change cookie settings" (localized).', 'biscotti-cmp' ),
			'class' => __( 'CSS class for the link element. Default: "biscotti-consent-link".', 'biscotti-cmp' ),
			'style' => __( 'Inline CSS styles for the link element. Default: empty.', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti_consent_link text="Change cookie settings"]',
	),
	array(
		'tag'         => '[biscotti_settings_link]',
		'description' => __( 'Renders a link that opens the granular cookie settings panel directly (skipping the main banner). Useful for detailed preference management.', 'biscotti-cmp' ),
		'attributes'  => array(
			'text'  => __( 'Link text. Default: "Change cookie settings" (localized).', 'biscotti-cmp' ),
			'class' => __( 'CSS class for the link element. Default: "biscotti-settings-link".', 'biscotti-cmp' ),
			'style' => __( 'Inline CSS styles for the link element. Default: empty.', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti_settings_link text="Cookie preferences"]',
	),
	array(
		'tag'         => '[biscotti_data_export]',
		'description' => __( 'Displays a GDPR Art. 15 data export button that allows visitors to download their stored consent data.', 'biscotti-cmp' ),
		'attributes'  => array(),
		'example'     => '[biscotti_data_export]',
	),
	array(
		'tag'         => '[biscotti_do_not_sell]',
		'description' => __( 'Renders a CCPA/CPRA "Do Not Sell or Share My Personal Information" opt-out link. Required for California compliance.', 'biscotti-cmp' ),
		'attributes'  => array(
			'text'  => __( 'Link text. Default: "Do Not Sell My Personal Information" (localized).', 'biscotti-cmp' ),
			'class' => __( 'CSS class for the link element. Default: "biscotti-dns-link".', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti_do_not_sell]',
	),
	array(
		'tag'         => '[biscotti_impressum]',
		'description' => __( 'Displays your Impressum (legal notice) generated via the Biscotti Legal Suite. The document is fetched from the API and cached locally.', 'biscotti-cmp' ),
		'attributes'  => array(
			'cache' => __( 'Enable caching. "true" or "false". Default: "true".', 'biscotti-cmp' ),
			'class' => __( 'CSS class for the container. Default: "biscotti-legal-document".', 'biscotti-cmp' ),
			'lang'  => __( 'Override language (2-letter code). Default: auto-detected.', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti_impressum]',
	),
	array(
		'tag'         => '[biscotti_privacy_policy]',
		'description' => __( 'Displays your Privacy Policy generated via the Biscotti Legal Suite. The document is fetched from the API and cached locally.', 'biscotti-cmp' ),
		'attributes'  => array(
			'cache' => __( 'Enable caching. "true" or "false". Default: "true".', 'biscotti-cmp' ),
			'class' => __( 'CSS class for the container. Default: "biscotti-legal-document".', 'biscotti-cmp' ),
			'lang'  => __( 'Override language (2-letter code). Default: auto-detected.', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti_privacy_policy]',
	),
	array(
		'tag'         => '[biscotti_cookie_policy]',
		'description' => __( 'Displays your Cookie Policy generated via the Biscotti Legal Suite. The document is fetched from the API and cached locally.', 'biscotti-cmp' ),
		'attributes'  => array(
			'cache' => __( 'Enable caching. "true" or "false". Default: "true".', 'biscotti-cmp' ),
			'class' => __( 'CSS class for the container. Default: "biscotti-legal-document".', 'biscotti-cmp' ),
			'lang'  => __( 'Override language (2-letter code). Default: auto-detected.', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti_cookie_policy]',
	),
	array(
		'tag'         => '[biscotti_embed]',
		'description' => __( 'Renders a placeholder container for a custom service that requires consent before loading. The content is blocked until the visitor grants consent for the service category.', 'biscotti-cmp' ),
		'attributes'  => array(
			'service' => __( 'Required. The service slug (e.g. "wistia-video", "hubspot-chat"). Must match a configured service.', 'biscotti-cmp' ),
			'class'   => __( 'CSS class for the container. Default: "biscotti-embed-container".', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti_embed service="wistia-video"]',
	),
	array(
		'tag'         => '[biscotti-document]',
		'description' => __( 'Generic document shortcode used by the "Assign to page" admin flow. Renders any legal document by type. Supports all document types available in the Legal Suite.', 'biscotti-cmp' ),
		'attributes'  => array(
			'type'  => __( 'Required. Document type: "impressum", "privacy_policy", "privacy-policy", "cookie_policy", "cookie-policy", "agb", or "terms".', 'biscotti-cmp' ),
			'cache' => __( 'Enable caching. "true" or "false". Default: "true".', 'biscotti-cmp' ),
			'class' => __( 'CSS class for the container. Default: "biscotti-legal-document".', 'biscotti-cmp' ),
			'lang'  => __( 'Override language (2-letter code). Default: auto-detected.', 'biscotti-cmp' ),
		),
		'example'     => '[biscotti-document type="privacy_policy"]',
	),
);
?>

<div class="biscotti-page biscotti-page-shortcodes">
	<?php
	$page_title = __( 'Shortcodes', 'biscotti-cmp' );
	include __DIR__ . '/partials/page-header.php';
	?>

	<p class="biscotti-page-description">
		<?php esc_html_e( 'Use these shortcodes to embed Biscotti elements in your pages and posts. Click the "Copy" button to copy a shortcode to your clipboard.', 'biscotti-cmp' ); ?>
	</p>

	<div class="biscotti-shortcodes-list">
		<?php foreach ( $shortcodes as $shortcode ) : ?>
			<div class="biscotti-shortcode-card">
				<div class="biscotti-shortcode-header">
					<code class="biscotti-shortcode-tag"><?php echo esc_html( $shortcode['tag'] ); ?></code>
					<button
						type="button"
						class="button button-small biscotti-copy-btn"
						data-copy-text="<?php echo esc_attr( $shortcode['example'] ); ?>"
					>
						<?php esc_html_e( 'Copy', 'biscotti-cmp' ); ?>
					</button>
				</div>

				<p class="biscotti-shortcode-description">
					<?php echo esc_html( $shortcode['description'] ); ?>
				</p>

				<?php if ( ! empty( $shortcode['attributes'] ) ) : ?>
					<div class="biscotti-shortcode-attributes">
						<h4><?php esc_html_e( 'Attributes', 'biscotti-cmp' ); ?></h4>
						<dl>
							<?php foreach ( $shortcode['attributes'] as $attr_name => $attr_desc ) : ?>
								<dt><code><?php echo esc_html( $attr_name ); ?></code></dt>
								<dd><?php echo esc_html( $attr_desc ); ?></dd>
							<?php endforeach; ?>
						</dl>
					</div>
				<?php endif; ?>

				<div class="biscotti-shortcode-example">
					<h4><?php esc_html_e( 'Usage Example', 'biscotti-cmp' ); ?></h4>
					<div class="biscotti-code-block">
						<code><?php echo esc_html( $shortcode['example'] ); ?></code>
						<button
							type="button"
							class="button button-small biscotti-copy-btn"
							data-copy-text="<?php echo esc_attr( $shortcode['example'] ); ?>"
						>
							<?php esc_html_e( 'Copy', 'biscotti-cmp' ); ?>
						</button>
					</div>
				</div>
			</div>
		<?php endforeach; ?>
	</div>
</div>
