/* Listing pattern */

@import "./variables.scss";

.ct-listing {
    font-size: var(--font-size-s);
    min-width: 65%;
    // Some parts of Cockpit still float (Docker) and need clearing
    clear: both;

    > header {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        flex-flow: wrap;

        > :only-child {
            flex: auto;
        }
    }

    + .ct-listing {
        margin-top: 1rem;
    }

    select, .pf-c-button, .dropdown, input {
        font-size: var(--pf-global--FontSize--md);
    }
}

.listing-ct-heading,
.listing-ct-actions {
    margin: 0.5rem 0;
}

.listing-ct-heading,
.listing-ct-simplebody-actions {
    flex: auto;
    padding: 0.25rem 1em 0.25rem 0;
}

.ct-listing > table > thead h3 {
    font-size: var(--pf-global--FontSize--2xl);
    padding: 1rem 0;
    font-weight: 400;
    margin-top: 0;
    position: relative;

    > .pull-right {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        right: 0;
    }
}

.ct-listing > table > thead td {
    padding-top: $listing-ct-padding * 2;
}

.ct-listing > table > thead:first-child td {
    padding-top: 0;
}

.ct-listing > table > thead td > a {
    line-height: 30px;
    padding: $listing-ct-padding 0 $listing-ct-padding;
}

.ct-listing > table > thead th {
    font-size: var(--pf-global--FontSize--md);
    font-weight: var(--pf-global--FontWeight--bold);
    padding: $listing-ct-padding $listing-ct-padding * 2;
}

.ct-listing > table > thead th:first-child {
    padding-left: $listing-ct-padding * 2;
}

.ct-listing > table > thead th:last-child {
    text-align: right;
}

/* A listing item is a row in the table */
tbody > tr.listing-ct-item {
    border: 1px solid transparent;
    border-top: 1px solid var(--color-ct-list-border);
    cursor: pointer;
}

.ct-listing > table > tbody:last-child {
    border-bottom: 1px solid var(--color-ct-list-border);
}
.ct-listing > table > tbody + thead {
    border-top: 1px solid var(--color-ct-list-border);
}
.ct-listing > table > tbody.open:last-child {
    border-bottom: none;
}
.ct-listing > table > tbody.open + thead {
    border-top: none;
}

tbody > tr.listing-ct-item.listing-ct-warning {
    background-color: $listing-ct-warning-color;
}

tbody.open > tr.listing-ct-item,
tbody.open > tr.listing-ct-panel {
    background-color: $listing-ct-active;
    border-bottom: none;
    border-top: none;
    border-left: 1px solid $listing-ct-border;
    border-right: 1px solid $listing-ct-border;
    transition: all 200ms;
}

tbody.open > tr.listing-ct-item td,
tbody.open > tr.listing-ct-item th {
    border-top: 1px solid $listing-ct-border;
}

tbody.open td div.listing-ct-head {
    background-color: $color-pf-white;
    align-items: flex-end;
}

tbody.open > .listing-ct-panel > td > .listing-ct-body {
    border: none;
    overflow: auto;
}

tbody.open > tr.listing-ct-panel + tr.listing-ct-body {
    border-top: none;
}

tbody.open > tr.listing-ct-panel td div.listing-ct-head {
    border: none;
    border-bottom: 1px solid $listing-ct-border;
    padding-top: 0;
}

/* only highlight the row if navigation is available */
tbody:not(.open) > tr.listing-ct-item:not(.listing-ct-nonavigate):hover {
    background-color: $listing-ct-hover;
}

/* if we can't navigate to a row but expand is available, highlight the caret */
tbody:not(.open) > tr.listing-ct-item.listing-ct-nonavigate:hover td.listing-ct-toggle {
    color: $listing-ct-hover-icon;
}

/* use hover color expanded rows even if navigation isn't available */
tbody.open > tr.listing-ct-item:hover,
tr.listing-ct-item.listing-ct-nonavigate:hover {
    background-color: $listing-ct-hover;
}

tr.listing-ct-item .listing-ct-toggle:not(:empty) {
    width: 35px;
    color: $color-pf-black-800;
}

/* Highlight toggle color when hovered or if the row is open */
.listing-ct-toggle:hover,
tbody.open .listing-ct-toggle {
    color: $listing-ct-active;
}

.listing-ct .listing-ct-toggle:empty {
    width: 0;
    padding: 0;
}

.listing-ct > thead > tr > .listing-ct-toggle + th,
.listing-ct-item > .listing-ct-toggle + td,
.listing-ct-item > .listing-ct-toggle + th {
    padding-left: $listing-ct-padding / 2;
    position: relative;
}

td.listing-ct-toggle button {
    border: 1px solid transparent;
}

td.listing-ct-toggle button:focus {
    color: var(--pf-global--Color--100) !important;
    border-color: var(--pf-global--BackgroundColor--light-300) !important;
    @-moz-document url-prefix() {
      /* Approximate Firefox's focus ring, for Firefox only */
      border: 1px dotted rgba(0, 0, 0, 0.75);
    }
}

td.listing-ct-toggle i {
    font-size: 17px;
}

td.listing-ct-toggle i:before {
    position: relative;
    content: "\f105";
    display: block;
}

tbody.open td.listing-ct-toggle i:before {
    content: "\f107";
    animation: listingCtToggleOpen 100ms ease-in-out;
    top: 1px;
}

@keyframes listingCtToggleOpen {
    0% {
       transform-origin: 50% 50%;
       transform: translate(0, -1px) rotate(-90deg);
    }
    100% {
       transform: translate(0, 0) rotate(0);
    }
}

/* Listing items have decent padding ... */
.listing-ct > thead > tr > th,
tr.listing-ct-item > th,
tr.listing-ct-item > td {
    padding: $listing-ct-padding * 1.5;
    vertical-align: text-top; /* baseline doesn't support wrapped lines */
}

tr.listing-ct-item > td {
    > .pf-c-button {
        margin-top: -7px;
        margin-bottom: -7px;
    }
}

/* Listing actions can be used directly as a cell */
tr.listing-ct-item td.listing-ct-actions,
td.listing-ct-actions {
    padding: $listing-ct-padding / 2 $listing-ct-padding;
    text-align: right;
    float: none;
}

/* if the entire row is selected, highlight */
tr.listing-ct-item.listing-ct-selected {
    background-color: $color-pf-blue-400;
    color: $color-pf-white;
    border-color: multiply($color-pf-black-200, $color-pf-blue-400);

    &:hover {
        background-color: multiply($color-pf-black-200, $color-pf-blue-400);
        border-color: multiply($color-pf-black-200, $color-pf-blue-400);
    }
}

tr.listing-ct-item.listing-ct-selected .badge {
    background-color: multiply($badge-bg, $color-pf-blue-400);

    &:hover {
        background-color: multiply($badge-bg, $color-pf-blue-500);
    }
}

.listing-ct-head .listing-ct-actions {
    margin: 0.25rem 0;
    order: -1;
}

/* The last column of a listing is always right aligned */
tr.listing-ct-item td:last-child {
    text-align: right;
}

div.listing-ct-panel {
    box-shadow: 1px 1px 1px 1px $listing-ct-open;
    margin-bottom: $listing-ct-spacing;
}

div.listing-ct-maybe {
    border: 1px dashed $listing-ct-border-maybe;
    box-shadow: none;
}

div.listing-ct-head {
    padding: $listing-ct-padding $listing-ct-padding 0 $listing-ct-padding;
    background-color: $listing-ct-open;
    border-color: $listing-ct-border;
    border-style: solid;
    border-width: 1px 1px 0 1px;
    overflow: hidden;
    align-items: center;
}
table:not(.pf-c-table) div.listing-ct-head {
    display: flex;
    flex-flow: row-reverse wrap;
}

div.listing-ct-head:last-child {
    padding-bottom: $listing-ct-padding;
}

div.listing-ct-maybe div.listing-ct-head,
div.listing-ct-maybe div.listing-ct-body {
    background-color: $color-pf-white;
    border: none;
}

tbody.active .listing-ct-head {
    border-top: $listing-ct-open-width solid var(--color-link);
}

.listing-ct-head h3 {
    font-weight: normal;
    font-size: 18px;
    margin-top: 0px;
    margin-left: $listing-ct-padding / 2;
    margin-bottom: $listing-ct-padding;
}

.listing-ct-head h3 i {
    float: left;
    padding-right: 7px;
}

.listing-ct-head .pf-c-nav {
    flex: auto;
}

/* To display info instead of tabs */
.listing-ct-head dl {
    display: inline-block;
    height: 1.6em;
    margin-bottom: 5px;
    white-space: nowrap;
    margin-right: 45px;
    margin-left: 5px;
}

.listing-ct-head dt {
    font-weight: normal;
    display: inline;
    margin-right: 0.5em;
    color: $listing-ct-metadata;
}

.listing-ct-head dd {
    display: inline;
    color: black;
}

.listing-ct-body {
    padding: $listing-ct-padding * 2 $listing-ct-padding + $listing-ct-spacing;
    border: 1px solid $listing-ct-border;
    background-color: $color-pf-white;
}

.listing-ct-inline > td > .listing-ct-body {
    border: none;
    padding-top: 0px;
    padding-left: $listing-ct-padding * 2;
    padding-bottom: 0px;
}

.listing-ct-inline > h3 {
    border-top: 1px solid $listing-ct-border;
    padding-top: 20px;
    margin-top: 30px;
}

.listing-ct-inline > h3:first-child {
    border-top: none;
    padding-top: 0px;
    margin-top: 20px;
}

.listing-ct-actions {
    float: right;
    min-height: 26px;
}

.listing-ct-status {
    float: right;
    clear: right;
}

.listing-ct-error {
    border-top: 1px solid $listing-ct-border;
    border-left: 1px solid $listing-ct-border;
    border-right: 1px solid $listing-ct-border;
}

.listing-ct-error.alert {
    margin-bottom: 0;
}

.listing-ct-body tt {
    font-size: 12px
}

.listing-ct-body dl {
    margin: 0;
}

.listing-ct-body dl dd dl.inline-dl dt,
.listing-ct-body dt {
    clear: left;
    float: left;
    width: 100px;
    min-height: 26px;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: $listing-ct-metadata;
    font-weight: normal;
}

.listing-ct-body dt {
    text-align: right;
}

.listing-ct-body dl dd dl dt {
    text-align: left;
}

.listing-ct-body dd {
    margin-left: 110px;
    min-height: 26px;
    max-width: 1000px;
    text-overflow: ellipsis;
}

.listing-ct-body dl.full-width dt {
    text-align: left;
    min-width: none;
    max-width: none;
    float: none;
    width: auto;
}

.listing-ct-body dl.full-width dd {
    margin-left: 0px;
}

.ct-listing > table > tbody {
    > tr > td:first-child {
        position: relative;
        transition: all 100ms ease-out;

        &::before,
        &::after {
            content: "";
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            opacity: 0;
            pointer-events: none;
            transition: all 300ms;
        }

        &::after {
            right: auto;
            width: 0;
            background-color: var(--pf-global--active-color--100);
        }
    }

    /* Nudge blue line above row border */
    > tr:not(:first-child) > td:first-child {
        &::after {
            top: -1px;
        }
    }

    &.open > tr > td:first-child {
        transition: all 100ms ease-in;

        &::before,
        &::after {
            opacity: 1;
        }

        &::after {
            width: 3px;
        }
    }

    &.open {
        transition: all 100ms ease-in;
        box-shadow: 0 0.3125rem 0.625rem -0.25rem rgba(3,3,3, 0.25);
    }
}

/* By default these are hidden */
/* (HACK: Special-case the user auth dialog) */
tbody:not(.ssh-key-body) > tr.listing-ct-head,
tbody > tr.listing-ct-panel,
tbody > tr.listing-ct-body {
    display: none;

    > td {
        /* Compensate for the left-side blue highlight */
        padding-left: 3px;
    }
}

/* ... unless they are in the right state */
tbody.open > tr.listing-ct-head,
tbody.open > tr.listing-ct-panel,
tbody.open > tr.listing-ct-body {
    display: table-row;
}

/* Animate the listing head & the last visible body */
/* (Switching tabs will adds new listing-ct-bodys & toggle visibility) */
tbody.open div.listing-ct-head,
tbody.open div.listing-ct-head + div.listing-ct-body:not([hidden]):last-child {
    animation: listingCtShow 100ms ease-in-out;
}

@keyframes listingCtShow {
    0% {
        margin-bottom: 0;
        margin-top: 0;
        max-height: 0;
        opacity: 0;
        padding-bottom: 0;
        padding-top: 0;
        line-height: 0;
    } 50% {
        opacity: 0;
        line-height: 1;
    }
    100% {
        max-height: 100vh;
        opacity: 1;
    }
}

/* Turn off animation if requested by the browser/OS (where supported) */
@media (prefers-reduced-motion: reduce) {
    tbody.open td.listing-ct-toggle i:before,
    tbody.open div.listing-ct-head,
    tbody.open div.listing-ct-body {
        animation: none;
    }
}

tbody.open tr.listing-ct-head {
    border-color: $listing-ct-border;
    border-style: solid;
    border-width: 1px 1px 0 1px;
    border-top: $listing-ct-open-width solid var(--color-link);
    background-color: $listing-ct-open;
}

tr.listing-ct-head + tr.listing-ct-head {
    border-top: none;
}

tr.listing-ct-head + tr.listing-ct-head td {
    padding: 0px $listing-ct-padding 0px $listing-ct-padding;
}

tr.listing-ct-body td {
    padding: $listing-ct-padding * 2 $listing-ct-padding + $listing-ct-spacing;
    font-size: var(--font-size-s);
}

.listing-ct-empty {
    color: var(--color-subtle-copy);
    text-align: center;
    border-top: 1px solid $listing-ct-border-light;
    border-bottom: 1px solid $listing-ct-border-light;
}

/* Used at the end of a group of tbody to show an 'empty' message */
thead.listing-ct-empty td,
.ct-listing > table > thead.listing-ct-empty td {
    padding: $listing-ct-padding;
}

tbody + thead.listing-ct-empty {
    display: none;
}

/* Listing pattern defaults to using full width of parent */
.listing-ct-wide {
    width: 100%;
}

div.listing-ct-head {
    overflow: visible;
}

.listing-ct-head .btn-group,
.listing-ct-head button:not(.dropdown-toggle) {
    margin-left: 0.3em;
}

tbody tr.listing-ct-noexpand {
    cursor: default;
}

.listing-ct-item td,
.listing-ct-item th,
.listing-ct-body {
    /* Force wraps when words are too long */
    overflow-wrap: break-word;
    hyphens: auto;
}
.listing-ct-item td,
.listing-ct-item th {
    max-width: calc(100vw - 18rem);
}
.listing-ct-body {
    /* 42 = (20px padding + 1px border) * 2 */
    max-width: calc(100vw - 42px);
}
