<?php
/**
 * Page shell for our full-screen template pages
 * (password-prompt.php, cart-conflict-prompt.php).
 *
 * Classic themes: use the theme's real header/footer (get_header/get_footer) —
 * it works fine and keeps full brand chrome.
 *
 * Block (FSE) themes: get_header() no-ops there, and hand-rendering the theme's
 * block header/footer parts breaks differently on every theme (layout styles,
 * wrappers, etc.). So for block themes we render our OWN minimal, theme-agnostic
 * shell instead — wp_head()/wp_footer() still run (our styles, WooCommerce
 * notices, scripts all load), with just the site logo/name for brand continuity.
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Open the page: classic themes get the real theme header; block themes get our
 * minimal branded shell.
 */
function lean_csns_render_page_header() {
    if ( ! wp_is_block_theme() ) {
        get_header();
        return;
    }
    ?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
<style>
    .lean-csns-standalone__bar { display: flex; justify-content: center; align-items: center; padding: 28px 16px; }
    .lean-csns-standalone__bar img { max-height: 48px; width: auto; height: auto; }
    .lean-csns-standalone__site { font-size: 1.25rem; font-weight: 700; text-decoration: none; color: inherit; }
</style>
</head>
<body <?php body_class( 'lean-csns-standalone' ); ?>>
<?php wp_body_open(); ?>
<header class="lean-csns-standalone__bar">
    <?php
    // Custom logo when set, otherwise the site name — both are core, not theme-specific.
    if ( has_custom_logo() ) {
        echo get_custom_logo(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- core markup
    } else {
        printf(
            '<a class="lean-csns-standalone__site" href="%s">%s</a>',
            esc_url( home_url( '/' ) ),
            esc_html( get_bloginfo( 'name' ) )
        );
    }
    ?>
</header>
    <?php
}

/**
 * Close the page: classic themes get the real theme footer; block themes get our
 * minimal shell close.
 */
function lean_csns_render_page_footer() {
    if ( ! wp_is_block_theme() ) {
        get_footer();
        return;
    }
    ?>
<?php wp_footer(); ?>
</body>
</html>
    <?php
}
