@use "theme/globals" as *;
:host {
    --placeholder-color: var(--ion-placeholder-color);
    --toobar-background: var(--white);
    --button-color: var(--ion-text-color);
    --button-active-color: var(--gray-300);
    --background: var(--rte-editor-background);
}

:host-context(html.dark) {
    --color: var(--white);
    --button-color: var(--gray-200);
    --button-active-color: var(--gray-500);
    --toobar-background: var(--gray-900);
}

:host {
    height: var(--core-rte-height, auto);
    overflow: hidden;
    min-height: 200px; /* Just in case vh is not supported */
    min-height: 40vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    background: var(--background);
    border: 1px solid var(--stroke);
    border-radius: var(--mdl-shape-borderRadius-md);

    &:focus-within {
        border-color: var(--a11y-focus-color);
        border-width: 2px;
        outline: none !important;
    }

    .core-rte-editor, .core-textarea, textarea {
        outline: none !important;
    }

    .core-rte-editor-container {
        max-height: calc(100% - 46px);
        display: flex;
        flex-grow: 1;
        flex-direction: column;
        justify-content: space-between;
        &.toolbar-hidden {
            max-height: 100%;
        }

        .core-rte-info-message {
            padding: 5px;
            border-top: 1px solid var(--info);
            background: var(--background);
            flex-shrink: 1;

            .icon {
                color: var(--info);
            }
        }
    }

    .core-rte-editor, .core-textarea {
        padding: 2px;
        margin: 2px;
        width: calc(100% - 4px);
        resize: none;
        background-color: var(--background);
        color: var(--color);
        flex-grow: 1;
    }

    .core-rte-editor {
        -webkit-user-select: auto !important;
        user-select: auto !important;
        word-wrap: break-word;
        overflow-x: hidden;
        overflow-y: auto;
        cursor: text;
        ::ng-deep img {
            @include padding(null, null, null, 2px);
            max-width: 95%;
            width: auto;
        }
        &:empty:before {
            content: attr(data-placeholder-text);
            display: block;
            color: var(--placeholder-color);
            font-weight: bold;
        }

        // Make empty elements selectable (to move the cursor).
        ::ng-deep *:empty:after {
            content: '\200B';
        }
    }

    .core-textarea {
        position: relative;

        ::ng-deep textarea {
            margin: 0 !important;
            padding: 0;
            resize: none;
            overflow-x: hidden;
            overflow-y: auto;
            position: absolute;
            height: auto;
            top: 0;
            bottom: 0;
        }
    }

    div.core-rte-toolbar {
        display: flex;
        width: 100%;
        z-index: 1;
        flex-grow: 0;
        flex-shrink: 0;
        background-color: var(--toobar-background);
        border-top: 1px solid var(--stroke);

        swiper-container {
            width: 240px;
            flex-grow: 1;
            flex-shrink: 1;
        }

        button {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 36px;
            height: 36px;
            padding-right: 6px;
            padding-left: 6px;
            margin: 2px auto;
            font-size: 18px;
            background-color: var(--toobar-background);
            border-radius: var(--mdl-shape-borderRadius-xs);
            @include core-transition(background-color, 200ms);
            color: var(--button-color);
            cursor: pointer;

            &.toolbar-button-enable {
                width: 100%;
            }

            &:active, &[aria-pressed="true"] {
                background-color: var(--button-active-color);
            }

            &.toolbar-arrow {
                width: 28px;
                flex-grow: 0;
                flex-shrink: 0;
                opacity: 1;
                @include core-transition(opacity, 200ms);

                &:active {
                    background-color: var(--toobar-background);
                }

                &[disabled],
                &:disabled {
                    opacity: .5;
                }
            }
        }

        &.toolbar-hidden {
            visibility: hidden;
            height: 0;
            border: none;
        }
    }
}

:host-context(.keyboard-is-open) {
    min-height: 200px;
}

:host-context(.item-label-stacked) {
    margin-top: 10px;
}
