// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

@import "dom/scrollbar.less";

// TODO this could be a class
@mixin icon {
    background-repeat: no-repeat;
    background-color: var(--icon--color);
    content: "";
    display: inline-block;
    -webkit-mask-size: cover;
    mask-size: cover;
}

:host {
    #add-expression-button:before {
        content: var(--add-expression-button--content, "New Column");
        text-transform: uppercase;
        font-size: 0.8333333em;
    }

    .column-selector-column-title {
        display: flex;
        width: 100%;
        flex-direction: row !important;
        align-items: center;
    }

    .column_name {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 0 1 auto;
        padding-left: 23px;
        display: inline-block;
        align-items: center;
        line-height: normal;

        &:only-child {
            padding-right: 12px;
        }
        &.none:only-child {
            padding-left: 12px;
        }
    }

    .column-selector--spacer {
        width: 67px;
        flex: 0 100000000 67px;
    }

    // Inactive columns need to account for expression buttons, which won't be
    // the last child if it has a button
    #sub-columns .column-selector--spacer:last-child {
        width: 93px;
        flex: 0 100000000 93px;
    }

    .show-aggregate .column-selector--spacer {
        width: 0px;
    }

    .show-aggregate {
        .column_name:only-child {
            padding-right: 12px;
        }
    }

    #sub-columns .column_name:only-child {
        padding-right: 12px;
    }
}

:host {
    #add-expression {
        border: var(--column-add--border, 1px solid transparent);
        min-height: 24px;
        flex-direction: row;
        background-color: #8b868045;
        border-radius: 2px;
        display: flex;
        align-items: center;
        margin-right: 7px;
        cursor: pointer;
        margin-bottom: 4px;

        // Button icon
        &:before {
            @include icon;
            width: 14px;
            height: 14px;
            margin-left: 12px;
            -webkit-mask-image: var(--add-expression-icon--mask-image);
            mask-image: var(--add-expression-icon--mask-image);
        }

        // Text label of the button e.g. "New Column"
        & > span {
            align-self: center;
            margin-left: 7.5px;
            text-overflow: ellipsis;
            white-space: nowrap;
            pointer-events: none;
        }

        &.modal-target,
        &.dragdrop-hover {
            color: var(--plugin--background);
            background-color: var(--icon--color);
            &:before {
                background-color: var(--plugin--background);
            }
        }
    }

    .dragdrop-highlight {
        .pivot-column-border,
        .column-selector-column-border {
            border: 1px solid var(--icon--color);
        }
    }

    .column-selector-column-border,
    .pivot-column-border {
        &.snap-drag-image {
            background-color: var(--plugin--background) !important;
            border: 1px solid var(--icon--color) !important;
            position: absolute !important;
            pointer-events: none;
            left: 0;
            z-index: -100000;
            width: 100%;
            height: 24px;

            .sort-icon,
            label,
            .dropdown-width-container {
                display: none;
            }

            .aggregate-selector-wrapper {
                min-width: 0px;
                max-width: 0px;
            }
        }
    }

    .column-selector-column-border {
        flex: 1 1 auto;
        overflow: hidden;
        position: relative;
        display: inline-flex;
        border: 1px solid transparent;
        border-radius: 2px;
    }

    .column-selector-border.snap-drag-image {
        & > *:not(.column_name) {
            display: none;
        }

        .column_name {
            padding-left: 23px !important;
        }
    }

    .dragdrop-highlight .column-selector-column .column-selector-border,
    .dragdrop-highlight
        .column-selector-column
        .column-selector-draggable.empty-named,
    .dragdrop-highlight
        #top_panel
        .pivot-column.column-empty
        .pivot-column-draggable {
        border-color: var(--icon--color);
    }

    .column-selector-column {
        display: flex;
        flex-direction: row-reverse;
        align-items: center;

        // Expression column toolbar buttons
        span.expression-edit-button,
        span.expression-delete-button {
            padding-top: 1px;
            font-family: var(--button--font-family, inherit);
            cursor: pointer;
            padding: 2px 4px 0 4px;
            margin-right: 4px;
            margin-left: auto;
            border-radius: 3px;
            &:hover,
            &.is-editing {
                background-color: var(--icon--color);
                &:before {
                    background-color: var(--plugin--background);
                    border-radius: 3px;
                }
            }
        }

        span.expression-delete-button {
            // padding-right: 1.5px;
            padding-left: 5px;
            margin-right: 8px;
            margin-left: auto;

            &:before {
                content: var(--column-close--content, "close");
            }
        }

        span.expression-delete-button + span.expression-edit-button {
            margin-left: 0px;
        }

        span.expression-edit-button:before {
            @include icon;
            height: 14px;
            width: 14px;
            -webkit-mask-image: var(--column-settings-icon--mask-image);
            mask-image: var(--column-settings-icon--mask-image);
        }

        .column-selector-draggable {
            cursor: move;
            display: flex;
            align-items: start;
            flex-grow: 1;
            color: inherit;
            box-sizing: border-box;
            flex-direction: row;
            align-items: stretch;
            position: relative;
            min-height: 28px;
            padding-bottom: 4px;

            &.show-aggregate {
                .column_name {
                    padding-left: 5px;
                }
            }

            &.empty-named {
                cursor: auto;
                padding-bottom: 0px;
                margin-bottom: 4px;
                min-height: 24px;
            }

            &:not(.empty-named) .column-selector-column-border:before {
                margin: 0px 0 0 6px; // TODO
                flex: 0 0 auto; // TODO
                @include icon;
                height: 12px;
                width: 5px;
                -webkit-mask-image: var(--column-drag-handle--mask-image);
                mask-image: var(--column-drag-handle--mask-image);
            }
        }
    }

    .is_column_active.inactive {
        min-width: 0px;
        margin: 0 6px 0 0;
    }

    .is_column_active {
        display: inline-flex;
        overflow: hidden;
        padding-bottom: 4px;
        flex: 0 0 auto;
        cursor: pointer;
        font-size: var(--column-selector--font-size, 14px);
        font-family: var(
            --column-selector--font-family,
            var(--button--font-family, inherit)
        ) !important;

        &.select-mode {
            margin: 0 6.5px;
            // Width of the icon, which is not always present
            min-width: 14px;
        }

        &,
        &.toggle-mode {
            margin: 0 6.5px;
            min-width: 14px;
        }
    }

    #selected-columns {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    #active-columns,
    #sub-columns {
        display: flex;
        flex: 0 1 auto;
        overflow-x: hidden !important;
        overflow-y: scroll;
        min-height: 20%;
        @include scrollbar;
    }

    #sub-columns:before {
        font-size: var(--label--font-size, 0.75em);
        padding: var(--column_type--padding, 0px 0px 0px 0px);
        position: absolute;
        margin-top: 14px;
        top: 0;
        content: var(--all-columns-label--content, "All Columns");
    }

    #sub-columns .scroll-panel-container:first-child {
        margin-top: 28px;
        margin-bottom: 4px;
    }

    #sub-columns .column-selector-column.column-selector-column-hidden {
        overflow: hidden;
        height: 0;
        margin-bottom: 0px;
    }

    #sub-columns {
        position: relative;
        flex: 0 10000000 auto;
    }

    #active-columns {
        display: flex;
        padding-bottom: 8px;
    }

    #active-columns,
    #column_settings_sidebar {
        width: 100%;
        .is_column_active:before {
            @include icon;
        }

        .is_column_active.select-mode {
            &:before {
                width: 14px;
                height: 14px;
                -webkit-mask-image: var(--column-radio-on--mask-image);
                mask-image: var(--column-radio-on--mask-image);
            }

            &:not(.required):hover:before {
                -webkit-mask-image: var(--column-radio-hover--mask-image);
                mask-image: var(--column-radio-hover--mask-image);
            }
        }

        .is_column_active.toggle-mode {
            &:before {
                width: 14px;
                height: 14px;
                -webkit-mask-image: var(--column-checkbox-on--mask-image);
                mask-image: var(--column-checkbox-on--mask-image);
            }

            &:not(.required):hover:before {
                -webkit-mask-image: var(--column-checkbox-hover--mask-image);
                mask-image: var(--column-checkbox-hover--mask-image);
            }
        }

        .is_column_active {
            &.required {
                // color: var(--inactive--color, #ccc);
                opacity: 0.3;
                cursor: not-allowed;
                cursor: initial;
            }

            &.inactive:before {
                content: "";
                background: none;
            }
        }

        // .column-selector-column[data-index="0"]:before {
        //     content: var(--column-selector-column-0--label, attr(data-label));
        // }

        // .column-selector-column[data-index="1"]:before {
        //     content: var(--column-selector-column-1--label, attr(data-label));
        // }

        // .column-selector-column[data-index="2"]:before {
        //     content: var(--column-selector-column-2--label, attr(data-label));
        // }

        // .column-selector-column[data-index="3"]:before {
        //     content: var(--column-selector-column-3--label, attr(data-label));
        // }

        // .column-selector-column[data-index="4"]:before {
        //     content: var(--column-selector-column-4--label, attr(data-label));
        // }

        // .column-selector-column[data-index="5"]:before {
        //     content: var(--column-selector-column-5--label, attr(data-label));
        // }

        .column-selector-column {
            position: relative;

            .column-selector-draggable {
                width: calc(100% - 27px);
            }

            .column-selector-column-border {
                border-color: var(--inactive--color);
                background-color: var(--plugin--background);
            }

            &:before {
                font-size: var(--label--font-size, 0.75em);
                left: 0px;
                padding: var(--column_type--padding, 0px 0px 0px 0px);
                position: absolute;
                margin-top: -43px;
                content: var(--default-column-title, attr(data-label));
            }

            &[data-label] {
                margin-top: 22px;
            }
        }
    }

    .dragover,
    .column-selector-column .column-selector-draggable.empty-named {
        background-color: #8b868045;
        border-color: transparent;
        border-radius: 2px;
    }

    .dragover-container .is_column_active {
        opacity: 0;
        margin: 0 6px 0 0;
        min-width: 0px;
        width: 0px;
    }

    .column-selector-column .column-selector-draggable.dragover {
        border: 1px solid var(--icon--color);
        position: relative;
        &:before {
            content: " ";
            position: absolute;
            z-index: -1;
            top: 5px;
            left: 5px;
            right: 5px;
            bottom: 5px;
            border-radius: 2px;
            background-color: var(--icon--color);
            opacity: 0.3;
        }

        & > * {
            opacity: 0;
        }
    }

    .column-selector-column {
        .column-selector-column-border {
            background-color: #8b868045;
            border: 1px solid transparent;
            align-items: center;
        }
    }

    #active-columns .column-selector-column.dragdrop-hover,
    #active-columns.dragdrop-highlight .column-selector-column,
    .column-selector-column.dragdrop-hover {
        .column-selector-column-border {
            border-color: var(--icon--color);
        }
    }

    // Inactive Columns are the columns in the column selector not currently
    // selected for the `columns` field of the `ViewConfig`.
    #sub-columns {
        padding-bottom: 8px;
        // & > div:not(:empty) {
        //     margin-bottom: 6px;
        // }

        &:empty {
            display: none;
            margin: 0px;
        }

        .is_column_active:before {
            @include icon;
        }

        .is_column_active.select-mode {
            &:before {
                width: 14px;
                height: 14px;
                -webkit-mask-image: var(--column-radio-off--mask-image);
                mask-image: var(--column-radio-off--mask-image);
            }
            &:hover:before {
                -webkit-mask-image: var(--column-radio-hover--mask-image);
                mask-image: var(--column-radio-hover--mask-image);
            }
        }

        .is_column_active.toggle-mode {
            &:before {
                width: 14px;
                height: 14px;
                -webkit-mask-image: var(--column-checkbox-off--mask-image);
                mask-image: var(--column-checkbox-off--mask-image);
            }

            &:hover:before {
                -webkit-mask-image: var(--column-checkbox-hover--mask-image);
                mask-image: var(--column-checkbox-hover--mask-image);
            }
        }

        .column-selector-column {
            .column-selector-draggable {
                width: calc(100% - 27px);
            }
        }
    }
}
