<?php
/**
 * File Path: includes/compat/compat-newspaper.php
 * Newspaper Theme (tagDiv) Compatibility -- loaded when get_template() === 'newspaper'.
 * Findings reference: PATCHES/COMPAT-WORKLOG.md -- NP-001 through NP-005.
 * @package My_Book_Showroom
 * @since   1.0.0
 */

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

/**
 * NP-001 -- tagDiv inline typography cascade.
 * tagDiv outputs user-configured typography as inline <style> blocks in <head>,
 * which render after mbs-compat.css and reverse load order. This inline block
 * fires at priority 99, printing after tagDiv's block and re-asserting MBS values.
 */
add_action( 'wp_enqueue_scripts', static function () {

	if ( ! wp_style_is( 'mbs-front', 'enqueued' ) ) {
		return;
	}

	$css = '
		/* NP-001: neutralise tagDiv inline typography cascade inside .mbs-wrapper */

		/* Paragraph margins */
		.td-post-content .mbs-wrapper p {
			margin: 0 0 0.75em;
			line-height: 1.6;
		}
		.td-post-content .mbs-wrapper p:last-child {
			margin-bottom: 0;
		}

		/* Link color — re-assert MBS brand color over tagDiv\'s user-configured value */
		.td-post-content .mbs-wrapper a {
			color: var(--mbs-link, #4AABB8);
			text-decoration: none;
		}
		.td-post-content .mbs-wrapper a:hover,
		.td-post-content .mbs-wrapper a:focus {
			color: var(--mbs-accent, #4AABB8);
		}

		/* Retailer buy button — restore button colors overridden by link rule above */
		.td-post-content .mbs-wrapper a.mbs-retailer-btn {
			color: var(--mbs-button-text, #FFFFFF);
			background-color: var(--mbs-button-bg, #2C3E6B);
			text-decoration: none;
		}

		/* Format tabs */
		.td-post-content .mbs-wrapper a.mbs-format-tab {
			text-decoration: none;
		}

		/* Headings — re-assert MBS margin rhythm over tagDiv heading rules */
		.td-post-content .mbs-wrapper h1,
		.td-post-content .mbs-wrapper h2,
		.td-post-content .mbs-wrapper h3,
		.td-post-content .mbs-wrapper h4,
		.td-post-content .mbs-wrapper h5,
		.td-post-content .mbs-wrapper h6 {
			margin: 0 0 0.5em;
			line-height: 1.3;
		}
	';

	wp_add_inline_style( 'mbs-front', $css );

}, 99 );

/**
 * NP-003 note -- tagDiv Composer page builder (non-standard rendering path).
 * Standard single posts call the_content() normally; this file's fixes apply.
 * On Composer-built pages, confirm .td-post-content is still the content wrapper.
 * Full analysis in PATCHES/COMPAT-WORKLOG.md -- NP-003.
 */
