/* The site's sort dropdown (SortDropdown.tsx) and the sort direction arrow it shares with
   other sort controls outside a table. A holder may set --control-height, which a compact button
   takes as its height. */

/* A sort dropdown: a button naming the option, joined to the list's arrow as one dropdown button split
   in two, then the direction arrow. A long text is cut short with an ellipsis at the button's cap. */
.sort-dropdown
{
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    /* Takes clicks inside a holder that lets clicks pass through to what lies under it
       (pointer-events: none). */
    pointer-events: auto;

    /* The arrows' hover holders keep their size and stretch to the button's height, so the hit area
       of the direction arrow 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 button'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 button joins it, with the line between them drawn once, by the button. */
    .labeled-dropdown .dropdown-button
    {
        height: 100%;
        border-left: none;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
    }
}

/* The button: the shared dropdown button's look, square on its right, where the list's arrow joins it.
   Its widest, 16rem, holds most option texts, judged by eye and can be tuned; a longer text ends in
   an ellipsis, whole in its hover.
   styles-other-component: the button is the sort dropdown's own, wearing the shared dropdown
   button's CSS class for its look. */
.sort-dropdown-button.dropdown-button
{
    min-width: 0;
    max-width: 16rem;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;

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

/* The button's text and the hidden texts of every text it can read share one grid cell, so the button
   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-dropdown-button-texts
{
    display: grid;
    min-width: 0;
    justify-items: start;
}

/* Each text in the button's grid cell: on one line, cut short with an ellipsis where the button's
   width runs out. */
.sort-dropdown-button-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 button's width, one per option the button can read. */
.sort-dropdown-button-reserved-text
{
    visibility: hidden;
}

/* The button's hover while the button 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-dropdown-button-text-fits-tooltip
{
    visibility: hidden;
}

/* Before any option is chosen the arrow is hidden, keeping its place. */
.sort-dropdown-direction.sort-dropdown-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-dropdown-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-dropdown-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 thin arrow of the tables' headers: 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;
    }
}

/* A compact button, as tall as the --control-height its holder sets, such as a heading's 1.5rem
   line: its halves' text centered in that height, so the button and the list's arrow are one height,
   and their corners 6px, the usual button's 8px on its 1.9rem height scaled to 1.5rem, so the
   shorter button keeps its shape rather than turning into a pill. */
.sort-dropdown-compact
{
    /* styles-other-component: the halves are the shared dropdown button's. */
    .dropdown-button
    {
        padding-top: 0;
        padding-bottom: 0;
    }

    /* styles-other-component: the button's left corners. */
    .sort-dropdown-button.dropdown-button
    {
        border-top-left-radius: 6px;
        border-bottom-left-radius: 6px;
    }

    /* styles-other-component: the half of the button with the list's arrow, as tall as the button by the same height
       rather than as its arrow's line and borders, its right corners as above. */
    .labeled-dropdown .dropdown-button
    {
        height: var(--control-height);
        border-top-right-radius: 6px;
        border-bottom-right-radius: 6px;
    }

    /* The direction arrow, no taller than the button. */
    .sort-dropdown-direction
    {
        min-height: 0;
    }
}
