<?php

namespace FleekDash\Admin\Editor;

/**
 * Editor CSS Management
 *
 * Handles CSS customization for both TinyMCE (Classic Editor)
 * and Gutenberg (Block Editor).
 *
 * @package FleekDash\Admin\Editor
 * @since 2.2.0
 */
class EditorCSSManager
{
    /**
     * Get TinyMCE custom styles
     *
     * @return string CSS content for TinyMCE editor
     */
    public static function getTinyMCEStyles()
    {
        return 'body { font-family: Inter, sans-serif; font-size: 14px; background: transparent; } body * { background: transparent; color: var(--foreground) } p { font-size: 14px; line-height: 1.6; } h1, h2 { color: var(--card-foreground) }';
    }

    /**
     * Get Gutenberg Block Editor custom styles
     *
     * @return string CSS content for Gutenberg editor
     */
    public static function getGutenbergStyles()
    {
        return '

            html, body {
                    scrollbar-width: thin !important;
                    font-family: var(--font-family);
            }

             /* TRANSPARENT BACKGROUND STRATEGY - Let fleek-window handle background */
             html.light {
                    --card-foreground: var(--foreground) !important;
                    --foreground: var(--foreground) !important;
                    background-color: transparent !important;
                    color: var(--foreground) !important;
                }

             html.dark {
                    --card-foreground: white !important;
                    --foreground: #acb7cdcf !important;
                    background-color: transparent !important;
                    color: white !important;
                }



                .block-editor-iframe__body {
                    font-family: Inter, sans-serif !important;
                    font-size: 14.4px !important;
                    background: transparent !important;
                }
                .block-editor-iframe__body p {
                    font-size: 14.4px !important;
                    line-height: 1.9 !important;
                }

                .block-editor-iframe__body .wp-block-paragraph {
                    font-size: 14.4px !important;
                    line-height: 1.9 !important;
                }

                /* Placeholder styling for paragraph blocks */
                .block-editor-iframe__body .wp-block-paragraph [data-rich-text-placeholder]:before,
                .block-editor-iframe__body .wp-block-paragraph [data-rich-text-placeholder]:after {
                    color: #6e7790 !important;
                    opacity: 0.8 !important;
                    transition: none !important;
                }

                .block-editor-iframe__body h1.wp-block-post-title {
                    font-size: 2em !important;
                    line-height: 1.2em !important;
                }

                /* Placeholder and caret colors controlled by theme classes on .block-editor-iframe__html */

                /* Light mode placeholders */
                .block-editor-iframe__html:not(.dark) [data-rich-text-placeholder]:before,
                .block-editor-iframe__html:not(.dark) [data-rich-text-placeholder]:after,
                .block-editor-iframe__html.light [data-rich-text-placeholder]:before,
                .block-editor-iframe__html.light [data-rich-text-placeholder]:after,
                .rich-text [data-rich-text-placeholder]:after,
                p.block-editor-default-block-appender__content {
                    color: #6e7790 !important;
                    opacity: 0.6 !important;
                }

                /* Dark mode placeholders */
                .block-editor-iframe__html.dark [data-rich-text-placeholder]:before,
                .rich-text [data-rich-text-placeholder]:after,
                .block-editor-iframe__html.dark [data-rich-text-placeholder]:after {
                    color: #6e7790 !important;
                    opacity: 0.7 !important;
                }

                /* Caret colors for light mode */
                .block-editor-iframe__html:not(.dark) .block-editor-rich-text__editable,
                .block-editor-iframe__html:not(.dark) .rich-text,
                .block-editor-iframe__html.light .block-editor-rich-text__editable,
                .block-editor-iframe__html.light .rich-text {
                    caret-color: var(--wp-admin-theme-color, #007cba) !important;
                }

                /* Caret colors for dark mode */
                .block-editor-iframe__html.dark .block-editor-rich-text__editable,
                .block-editor-iframe__html.dark .rich-text {
                    caret-color: var(--wp-admin-theme-color, #6e7790) !important;
                }

                /* CRITICAL: Disable transitions during theme switching in Gutenberg iframe */
                [data-theme-switching="true"] *,
                [data-theme-switching="true"] *::before,
                [data-theme-switching="true"] *::after {
                    transition: none !important;
                    animation: none !important;
                }

                /* Specific Gutenberg elements - disable transitions during theme switching */
                [data-theme-switching="true"] .block-editor-rich-text__editable,
                [data-theme-switching="true"] .block-editor-rich-text__editable *,
                [data-theme-switching="true"] .rich-text,
                [data-theme-switching="true"] .rich-text *,
                [data-theme-switching="true"] .components-button,
                [data-theme-switching="true"] .components-button *,
                [data-theme-switching="true"] .components-input-control,
                [data-theme-switching="true"] .components-input-control *,
                [data-theme-switching="true"] .components-popover,
                [data-theme-switching="true"] .components-popover *,
                [data-theme-switching="true"] .block-editor-block-list__layout,
                [data-theme-switching="true"] .block-editor-block-list__layout * {
                    transition: none !important;
                    animation: none !important;
                }

                .wp-block-more::before  {
    border-color: var(--border) !important;
 }

.wp-block-more input[type=text] {
    background: var(--background-20) !important;

 }

 .wp-block-separator {
    border-top: 2px solid var(--border) !important;
    border-radius: 0 !important;
}


                    .block-editor-iframe__body p,
                    .block-editor-iframe__body li,
                    .block-editor-iframe__body h3,
                    .block-editor-iframe__body h4,
                    .block-editor-iframe__body h5,
                    .block-editor-iframe__body h6 {
                        color: var(--foreground);
                        font-family: var(--font-family);
                    }

                    .block-editor-iframe__body h1,
                    .block-editor-iframe__body h2 {
                        color: var(--card-foreground);
                        font-family: var(--font-family);
                    }




  /* Scrollbar utility — auto gutter (no reserved column in editor canvas iframe) */
.block-editor-iframe__html {
  scrollbar-gutter: auto;
  overflow-y: auto;
  background: transparent;
}

.block-editor-iframe__html::-webkit-scrollbar  {
  width: 6px;
  height: 6px;
}

.block-editor-iframe__html::-webkit-scrollbar-track  {
  background: transparent;
}



.block-editor-iframe__html::-webkit-scrollbar-thumb:hover  {
  background: rgba(161, 161, 170, 0.7);
}

            ';
    }
}

