<?php

/**
 * LolaCore - Desktop Mode compatibility
 *
 * @package LolaCore
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore\Compat;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class DesktopMode
 *
 * Compatibility with the Desktop Mode plugin (wordpress.org/plugins/desktop-mode),
 * which renders wp-admin as a desktop shell.
 *
 * We deliberately consume none of its registration APIs: LolaCore keeps its own
 * floating widget and stays present in the shell exactly as it is in classic
 * wp-admin. This class only answers one question — is the current request being
 * painted inside one of the shell's windows?
 */
class DesktopMode
{
    /**
     * Whether this request is rendering inside a Desktop Mode window.
     *
     * The shell paints the desktop in the parent page and loads each open window
     * as an admin page in its own iframe. Both are admin pages, so an unguarded
     * `admin_enqueue_scripts` puts the floating widget in the parent (wanted) AND
     * in every window (not wanted) — five open windows means six Lola widgets,
     * five of them boxed inside a frame.
     *
     * Callers suppress the floating widget on true. Everything else LolaCore
     * enqueues must keep loading: our own admin screens open as shell windows and
     * need their assets.
     *
     * Guarded by `function_exists()` so this stays a no-op without Desktop Mode
     * installed. Its helper already verifies the user opted into desktop mode,
     * so a hand-typed query flag cannot trip it.
     */
    public static function isShellWindow(): bool
    {
        if (!\function_exists('desktop_mode_is_chromeless_request')) {
            return false;
        }

        return (bool) \desktop_mode_is_chromeless_request();
    }
}
