/**
 * entry.scss - Theme Base Entry Styles
 *
 * This source-code is part of Windows XP stuff for XFCE:
 * <<https://www.oddmatics.uk>>
 *
 * Author(s): Rory Fewell <roryf@oddmatics.uk>
 */

%entry,
entry
{
    %entry_basic, &
    {
        // NOTE: Adwaita only defines box-model stuff here, colours are done in the
        //       corresponding drawing/entries.scss file (so we do the same)
        //
        @include __wintc_apply_specific_props(
            $entry_styles,
            "border-style",
            "border-top-width",
            "border-right-width",
            "border-bottom-width",
            "border-left-width",
            "margin-top",
            "margin-right",
            "margin-bottom",
            "margin-left",
            "padding-top",
            "padding-right",
            "padding-bottom",
            "padding-left"
        );

        $l_border_bottom: __wintc_get_prop($entry_styles, "border-bottom-width");
        $l_border_top:    __wintc_get_prop($entry_styles, "border-top-width");

        min-height: calc(#{$_entry_height} - #{$l_border_bottom} - #{$l_border_top});

        @include entry(normal);

        // Icons inside of the entry
        //
        image
        {
            &.left  { margin-right: 6px; }
            &.right { margin-left:  6px; }
        }


        &.flat
        {
            &:focus,
            &:backdrop,
            &:disabled,
            &:backdrop:disabled,
            &
            {
                background-color: transparent;
                border-color:     transparent;
                border-radius:    0;
                min-height:       0;
                padding:          2px;
            }
        }

        &:focus
        {
            @include entry(focus);
        }

        &:disabled
        {
            @include entry(insensitive);
        }

        selection
        {
            @extend %selected_items;
        }

        // Entry error and warning style
        //
        @each $e_type, $e_color in (error, $error_color),
                                   (warning, $warning_color)
        {
            &.#{$e_type}
            {
                border-color: entry_focus_border($e_color);
                color:        $e_color;

                &:focus
                {
                    @include entry(focus, $e_color);
                }

                selection
                {
                    background-color: $e_color;
                }
            }
        }

        // Entry icons colors
        //
        image
        {
            color: mix($fg_color, $base_color, 80%);

            &:hover
            {
                color: $fg_color;
            }

            &:active
            {
                color: $selected_bg_color;
            }
        }

        &:drop(active)
        {
            &:focus, &
            {
                border-color: $drop_target_color;
                box-shadow:   inset 0 0 0 1px $drop_target_color;
            }
        }

        .osd &
        {
            @include entry(osd);

            &:focus
            {
                @include entry(osd-focus);
            }

            &:disabled
            {
                @include entry(osd-insensitive);
            }
        }
    }

    progress
    {
        background-color: transparent;
        background-image: none;
        border-radius:    0;
        border-width:     0 0 2px;
        border-color:     $progress_bg_color;
        border-style:     solid;
        box-shadow:       none;
        margin-left:      -3px;
    }

    // Linked entries
    //
    .linked:not(.vertical) > &
    {
        @extend %linked;
    }

    .linked:not(.vertical) > &:focus + &,
    .linked:not(.vertical) > &:focus + button,
    .linked:not(.vertical) > &:focus + combobox > box > button.combo
    {
        border-left-color: entry_focus_border();
    }

    .linked:not(.vertical) > &:focus.error + &,
    .linked:not(.vertical) > &:focus.error + button,
    .linked:not(.vertical) > &:focus.error + combobox > box > button.combo
    {
        border-left-color: entry_focus_border($error_color);
    }

    .linked:not(.vertical) > &:drop(active) + &,
    .linked:not(.vertical) > &:drop(active) + button,
    .linked:not(.vertical) > &:drop(active) + combobox > box > button.combo
    {
        border-left-color: $drop_target_color;
    }

    // Vertically linked entries
    // FIXME: take care of "colored" entries
    //
    .linked.vertical > &
    {
        @extend %linked_vertical;

        // Brighter border between linked entries
        //
        &:not(:disabled) + entry:not(:disabled),
        &:not(:disabled) + %entry:not(:disabled)
        {
            border-top-color: mix($borders_color, $base_color, 30%);

            &:backdrop
            {
                border-top-color: mix($backdrop_borders_color, $backdrop_base_color, 30%);
            }
        }

        // Brighter border between linked insensitive entries
        //
        &:disabled + %entry:disabled,
        &:disabled + entry:disabled
        {
            border-top-color: mix($borders_color, $base_color, 30%);
        }

        // Color back the top border of a linked focused entry following another entry.
        // :not(:only-child) is a specificity bump hack.
        //
        + %entry:focus:not(:only-child),
        + entry:focus:not(:only-child)
        {
            border-top-color: entry_focus_border();
        }

        + %entry:focus.error:not(:only-child),
        + entry:focus.error:not(:only-child)
        {
            border-top-color: entry_focus_border($error_color);
        }

        + %entry:drop(active):not(:only-child),
        + entry:drop(active):not(:only-child)
        {
            border-top-color: $drop_target_color;
        }

        // This takes care of coloring the top border of the focused entry subsequent widget.
        // :not(:only-child) is a specificity bump hack.
        //
        &:focus:not(:only-child)
        {
            + %entry,
            + entry,
            + button,
            + combobox > box > button.combo
            {
                border-top-color: entry_focus_border();
            }
        }

        &:focus.error:not(:only-child)
        {
            + %entry,
            + entry,
            + button,
            + combobox > box > button.combo
            {
                border-top-color: entry_focus_border($error_color);
            }
        }

        &:drop(active):not(:only-child)
        {
            + %entry,
            + entry,
            + button,
            + combobox > box > button.combo
            {
                border-top-color: $drop_target_color;
            }
        }
    }

    &.error
    {
        color: $error_color;
    }
}

treeview entry
{
    &:focus
    {
        // Specificity bump hack
        //
        &:dir(rtl), &:dir(ltr)
        {
            background-color:    $base_color;
            transition-property: color, background;
        }
    }

    &.flat, &
    {
        border-radius:    0;
        background-image: none;
        background-color: $base_color;

        &:focus
        {
            border-color: $selected_bg_color;
        }
    }
}

.entry-tag
{
    // Sizing
    //
    margin-top:    2px;
    margin-bottom: 2px;
    padding:       5px;


    // Side margins: compensate the entry padding with a negative margin
    // then the negative margin itself
    //
    :dir(ltr) &
    {
        margin-left: 8px;
        margin-right: -5px;
    }
    :dir(rtl) &
    {
        margin-left: -5px;
        margin-right: 8px;
    }

    border-style: none;

    $_entry_tag_color: $selected_fg_color;
    color:             $_entry_tag_color;

    $_entry_tag_bg:   $selected_bg_color;
    background-color: $_entry_tag_bg;

    &:hover
    {
        background-color: lighten($_entry_tag_bg, 10%);
    }

    &.button
    {
        background-color: transparent;
        color:            transparentize($_entry_tag_color, 0.3);
    }

    :not(:backdrop) &.button
    {
        &:hover
        {
            border: 1px solid $_entry_tag_bg;
            color:  $_entry_tag_color;
        }

        &:active
        {
            background-color: $_entry_tag_bg;
            color:            transparentize($_entry_tag_color, 0.3);
        }
    }
}
