/* The site's sort split button (SortSplitButton.tsx) and the sort direction arrow it shares with
   other sort controls outside a table. */

/* A sort split button: the option's name, joined to the list's arrow as one dropdown button split
   in two, then the sort's arrow. A long name is cut short with an ellipsis at the name's cap. */
.sort-split-button
{
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    pointer-events: auto;

    /* The arrows' hover holders keep their size and stretch to the name's height, so the sort's
       arrow's hit area does. styles-other-component: the shared tooltip's holders, which take no
       CSS class. */
    > *:not(:first-child)
    {
        display: flex;
        flex-shrink: 0;
        align-self: stretch;
    }

    /* The name's hover holder gives way to the room. styles-other-component: the shared tooltip's holder. */
    > :first-child
    {
        display: flex;
        min-width: 0;
    }

    /* styles-other-component: the shared dropdown's arrow-only button, square on its left, where
       the name joins it, with the line between them drawn once, by the name. */
    .labeled-dropdown .dropdown-button
    {
        height: 100%;
        border-left: none;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
    }
}

/* The name: the shared dropdown button's look, square on its right, where the list's arrow joins it.
   It is at most about as wide as the Codebase Knowledge table's frozen columns' headings, where it
   was first used, a visual choice that can be tuned; a longer name ends in an ellipsis, whole in its
   hover.
   styles-other-component: the name is the split button's own button, wearing the shared dropdown
   button's CSS class for its look. */
.sort-split-button-name.dropdown-button
{
    min-width: 0;
    max-width: 16rem;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;

    /* A remembered option's name, while the rows are in another order, in the low-emphasis text
       color, as the arrow beside it is dimmed. */
    &.sort-split-button-name-dimmed
    {
        color: var(--neutral-surface-low-emphasis-contrast-color);
    }
}

/* The name's text and the hidden texts of every name it can read share one grid cell, so the name
   is as wide as the widest, as the shared dropdown's button is, while each is cut short with an
   ellipsis where the room runs out. */
.sort-split-button-name-texts
{
    display: grid;
    min-width: 0;
    justify-items: start;
}

/* Each text in the name's grid cell: on one line, cut short with an ellipsis where the name's
   width runs out. */
.sort-split-button-name-text
{
    grid-area: 1 / 1;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The hidden texts that only reserve the name's width, one per option the name can read. */
.sort-split-button-name-reserved-text
{
    visibility: hidden;
}

/* The name's hover while the name fits: hidden, since it would only repeat it.
   styles-other-component: UseContentTruncation hands the tooltip this modifier CSS class while the
   name fits. */
.tooltip.sort-split-button-name-fits-tooltip
{
    visibility: hidden;
}

/* Before any option is chosen the arrow is hidden, keeping its place. */
.sort-split-button-direction.sort-split-button-direction-hidden
{
    visibility: hidden;
}

/* The sort's arrow, a button that sorts the other way: the headers' arrow in their text color,
   brightening to the primary color on hover, as a header's label does. */
.sort-split-button-direction
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: stretch;
    /* A hit area as tall as the dropdown beside it and wider than the icon, so a near miss lands
       on it; sizes judged by eye. */
    min-width: 1.5rem;
    min-height: 1.5rem;
    padding: 0 0.35rem;
    /* The hover background's rounded corners, judged by eye. */
    border-radius: 0.25rem;
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;

    /* With the pointer on the arrow, it turns gold on a lighter background. */
    &:hover
    {
        color: var(--primary-higher-emphasis-color);
        background: var(--neutral-high-emphasis-surface-color);
    }
    /* Pressed, the arrow brightens, as the site's other buttons do. */
    &:active
    {
        filter: brightness(130%);
    }

    /* Keyboard focus shows the site's gold ring. */
    &:focus-visible
    {
        outline: 2px solid var(--primary-higher-emphasis-color);
        outline-offset: 1px;
    }

    /* With an option remembered but the rows in another order, it is inert, dimmed as the
       site's disabled controls are, showing the remembered sort's way. */
    &.sort-split-button-direction-inert
    {
        opacity: 0.5;
        cursor: default;

        /* The inert arrow keeps its look with the pointer on it. */
        &:hover
        {
            color: inherit;
            background: none;
        }
        /* The inert arrow doesn't brighten when pressed. */
        &:active
        {
            filter: none;
        }
    }
}

/* A sort's direction arrow, the tables' headers' thin arrow: down for descending, flipped up for
   ascending, hidden while its sort isn't applied, keeping its room. */
.sort-direction-arrow
{
    display: inline-flex;
    transform: scaleY(1);
    /* ux-exception: the table's sort arrow flip (SortableTable.css), whose CSS class applies
       only inside a sortable table. */
    transition: transform 0.3s ease;

    @media (prefers-reduced-motion: reduce)
    {
        transition: none;
    }

    &.sort-direction-arrow-ascending
    {
        transform: scaleY(-1);
    }

    &.sort-direction-arrow-hidden
    {
        visibility: hidden;
    }
}
