<?php

/**
 * LolaCore — Authorize Application screen styles (LolaHub pairing).
 *
 * @package LolaCore
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore\Hub;

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

/**
 * Prevents long callback URLs from overflowing the WP core consent card.
 */
final class PairingAuthorizeStyles
{
    public function register(): void
    {
        \add_action('admin_enqueue_scripts', [$this, 'enqueue']);
    }

    public function enqueue(string $hook): void
    {
        if ($hook !== 'authorize-application.php') {
            return;
        }

        $css = '
            .auth-app-card .description,
            .auth-app-card .description code,
            .auth-app-card code {
                word-break: break-all;
                overflow-wrap: anywhere;
                white-space: normal;
                max-width: 100%;
            }
            .auth-app-card .description code {
                display: inline;
            }
        ';

        \wp_register_style(
            'lolacore-pairing-authorize',
            false,
            [],
            defined('LOLACORE_VERSION') ? LOLACORE_VERSION : '1.0.0'
        );
        \wp_enqueue_style('lolacore-pairing-authorize');
        \wp_add_inline_style('lolacore-pairing-authorize', $css);
    }
}
