@import "../../../../../backend/assets/less/core/boot.less";

@table-color: @input-color;
@table-bg: var(--bs-table-bg);
@table-striped-bg: var(--bs-table-striped-bg);
@table-toolbar-bg: @input-bg;

@table-header-color: @heading-color;
@table-header-bg: @tertiary-bg;

@table-border-color: @input-border;
@table-active-border: @primary-border;
@table-inactive-border: @primary-border;

.control-table {
    .table-container {
        border: 1px solid @table-border-color;
        border-radius: 4px;
        overflow: hidden;
        margin-bottom: 15px;

        &:last-child {
            margin-bottom: 0;
        }
    }

    &.active .table-container {
        border-color: @table-active-border;
    }

    table {
        width: 100%;
        border-collapse: collapse;
        table-layout: fixed;
        position: relative;

        td, th {
            padding: 0;
            font-size: 13px;
            color: @table-color;
        }

        [data-view-container] {
            padding: 5px 10px;
            width: 100%;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            min-height: 28px;
        }
    }

    table.headers {
        &:after {
            content: ' ';
            display: block;
            position: absolute;
            left: 1px;
            right: 1px;
            margin-top: -1px;
            border-bottom: 1px solid @table-border-color;
        }

        th {
            padding: 7px 10px;
            font-weight: normal;
            font-size: @font-size-base;
            color: @table-header-color;
            background: @table-header-bg;
            border-right: 1px solid @table-border-color;
            [data-view-container] {
                padding-bottom: 6px;
            }

            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;

            &:last-child {
                border-right: none;
            }
        }
    }

    &.active table.headers:after {
        border-bottom-color: @table-active-border;
    }

    table.data {
        td {
            border: 1px solid @table-inactive-border;

            .content-container {
                position: relative;
                padding: 1px;
            }

            &.active {
                background: @input-bg;

                .content-container {
                    box-shadow: inset 0 0 1px 1px @color-focus;

                    input {
                        background: transparent;
                        color: @input-color;
                    }
                }
            }
        }

        tr {
            background-color: @table-bg;

            &.error {
                background-color: var(--oc-table-active-bg, #fbecec)!important;

                td.active.error {
                    .content-container {
                        box-shadow: inset 0 0 1px 1px #ec0000;
                    }
                }
            }
        }

        tr:nth-child(2n) {
            background-color: @table-striped-bg;
        }
    }

    table.data {
        tr:first-child td {
            border-top: none;
        }

        tr:last-child td {
            border-bottom: none;
        }

        td:first-child {
            border-left: none;
        }

        td:last-child {
            border-right: none;
        }
    }

    .control-scrollbar {
        > div {
            .border-bottom-radius(4px);
            overflow: hidden;
        }

        table.data {
            tr:last-child td {
                border-bottom: 1px solid @table-border-color;
            }
        }
    }

    .toolbar {
        background: @table-toolbar-bg;
        border-bottom: 1px solid @table-border-color;
        padding: 3px;
        font-size: 0;
        white-space: nowrap;

        a.btn {
            .backend-toolbar-button();
            font-size: 14px;
            box-shadow: none;
            line-height: 30px;
            vertical-align: top;
        }

        a.btn, button {
            color: @toolbar-color;
            margin: 1px 0;
        }

        .table-search {
            float: right;
            margin: 0 3px 0 0;

            .table-search-input {
                height: auto;
                padding: 5px 13px 5px;
            }
        }

        a.table-icon {
            &:before {
                display: inline-block;
                content: ' ';
                width: 16px;
                height: 16px;
                margin-right: 8px;
                position: relative;
                top: 3px;
                background: transparent url(../images/table-icons.gif) no-repeat 0 0;
                background-size: 32px auto;
            }

            &.add-table-row-above:before {
                background-position: 0 -56px;
            }

            &.delete-table-row:before {
                background-position: 0 -113px;
            }
        }
    }

    &.active .toolbar {
        border-bottom-color: @table-active-border;
    }

    .pagination {
        ul {
            padding: 0;
            margin-bottom: 15px;

            li {
                list-style: none;
                padding: 4px 6px;
                border-radius: 2px;
                display: inline-block;
                margin-right: 5px;
                font-size: 12px;
                background: #ecf0f1;
                line-height: 100%;

                a {
                    text-decoration: none;
                    color: #95a5a6;
                }

                &.active {
                    background: @brand-primary;
                    a {
                        color: #fff;
                    }
                }
            }
        }
    }
}

@media only screen and (-moz-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-devicepixel-ratio: 1.5), only screen and (min-resolution: 1.5dppx) {
    .control-table .toolbar {
        a {
            &:before {
                background-position: 0px -9px;
                background-size: 16px auto;
            }

            &.add-table-row-above:before {
                background-position: 0 -39px;
            }

            &.delete-table-row:before {
                background-position: 0 -66px;
            }
        }
    }
}

/*
 * String and autocomplete editors
 */

.control-table {
    td[data-column-type=string],
    td[data-column-type=autocomplete] {
        input[type=text] {
            width: 100%;
            height: 100%;
            display: block;
            outline: none;
            border: none;
            padding: 5px 10px 6px;
        }
    }
}

ul.table-widget-autocomplete {
    background: @dropdown-bg;
    font-size: 13px;
    margin-top: 0;
    border: 1px solid @table-active-border;
    border-top: 1px solid @toolbar-border;
    .border-bottom-radius(4px);

    li a {
        padding: 5px 10px;
    }
}

/*
 * Checkbox editor
 */

.control-table {
    td[data-column-type=checkbox] {
        input[data-checkbox-element] {
            font-size: 1rem;
            margin-left: 10px;
        }
    }
}

/*
 * Dropdown editor
 */

.control-table {
    td[data-column-type=dropdown] {
        user-select: none;

        .dropdown-arrow() {
            .icon(@icon-angle-down);
            font-size: 13px;
            line-height: 100%;
            color: #95a5a6;
            position: absolute;
            top: 8px;
            right: 10px;
        }

        [data-view-container] {
            padding-right: 20px;
            position: relative;
            cursor: pointer;

            &:after {
                .dropdown-arrow();
            }

            &:hover:after {
                color: @link-color;
            }
        }

        [data-dropdown-open=true] {
            background: @primary-bg;
            [data-view-container]:after {
                .icon(@icon-angle-up);
            }
        }

        .content-container {
            outline: none;
        }
    }
}

/* Frameless control styles start */

.widget-field.frameless .control-table {
    .table-container {
        border-top: none;
        border-left: none;
        border-right: none;
        border-radius: 0;
    }

    .toolbar {
        background: transparent;
    }
}

/* Frameless control styles end */

html.cssanimations {
    .control-table td[data-column-type=dropdown] {
        [data-view-container].loading:after {
            background: url('../../../../../../modules/backend/assets/images/loader-transparent.svg') 50% 50%;
            background-size: 15px 15px;
            position: absolute;
            width: 15px;
            height: 15px;
            top: 6px;
            right: 5px;
            content: ' ';
            .animation(spin 1s linear infinite);
        }
    }
}

.table-control-dropdown-list {
    user-select: none;
    position: absolute;
    background: @dropdown-bg;
    border: 1px solid @table-active-border;
    border-top: none;
    padding-top: 1px;
    overflow: hidden;
    z-index: 1000;
    box-sizing: border-box;
    .border-bottom-radius(4px);

    ul {
        border-top: 1px solid @toolbar-border;
        padding: 0;
        margin: 0;
        max-height: 200px;
        overflow: auto;
    }

    li {
        list-style: none;
        font-size: 13px;
        color: @text-color;
        padding: 5px 10px;
        cursor: pointer;
        outline: none;

        &:hover,
        &:focus,
        &.selected {
            background: @color-focus;
            color: white;
        }
    }
}
