@import "../variables/dimensions";
@import "../variables/colors";
@import "icons";
@import "~bootstrap-sass/assets/stylesheets/bootstrap/mixins/border-radius";

.rc-form .form-group,
.form-element {
    margin-bottom: $form-group-vertical-offset;

    label {
        margin-bottom: $grid-gutter-width; //FIXME This style ruins layout of inline forms
        &.radio-inline,
        &.checkbox-inline {
            margin-bottom: 0;
        }
    }

    legend {
        margin-bottom: $grid-gutter-width;
    }

    .checkbox, .radio {
        margin-top: 0;
        margin-bottom: 0;
        label {
            margin-bottom: 0;
            word-wrap: break-word;
        }
    }
}

.rc-form .rc-form-group-noOffset {
    margin-bottom: 0;
}

.rc-form-inline {
    margin-left: (-$grid-gutter-width / 2);
    margin-right: (-$grid-gutter-width / 2);

    .form-group {
        margin-left: ($grid-gutter-width / 2);
        margin-right: ($grid-gutter-width / 2);
        margin-bottom: 0;
        //vertical-align: top; //FIXME Supposed to be top, uncomment when possible
    }

    label {
        margin-right: $grid-gutter-width;
        font-weight: normal;
    }

    .radio label,
    .checkbox label,
    label.checkbox-inline,
    label.radio-inline {
        margin-right: 0;
    }
}

.checkbox-inline,
.radio-inline,
.form-inline .radio,
.form-inline .checkbox {
    input {
        margin-right: 8px;
    }
}

.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
    margin-left: ($default-padding);
}

.rc-form .rc-list-checkbox, .rc-list-checkbox,
.rc-form .rc-list-radio, .rc-list-radio {
    margin: 0;
    white-space: nowrap;
    label {
        display: block; // overcome margin at bottom
    }
    .checkbox,
    .radio {
        margin: 0; // undo default margins on top and bottom
    }
}

.form-control {
    box-shadow: none;
}

textarea.form-control {
    resize: none;
}

.disabled-label {
    cursor: default !important;
}

.form-control-static {
    word-wrap: break-word;
}

.btn-group-justified {
    table-layout: auto;

    // fix double borders and border radius of nested buttons/multiSelect into justified button group
    > {
        :first-child:not(:last-child) {
            .multi-select {
                .btn {
                    @include border-right-radius(0);
                }
            }
        }
    }
    > {
        :not(:first-child):not(:last-child) {
            .multi-select {
                .btn {
                    @include border-left-radius(0);
                    @include border-right-radius(0);
                }
            }
        }
    }
    > {
        :last-child:not(:first-child) {
            .multi-select {
                .btn {
                    @include border-left-radius(0);
                }
            }

        }
    }

    > {
        :not(:first-child) {
            .multi-select {
                .btn {
                    border-left: 0;
                }
            }
            > .btn {
                border-left: 0;
            }
        }
    }
}

.multi-select {
    max-width: 100%;

    ul {
        margin: 0;
        padding: 0;
        list-style: none;
        width: 100%;
    }

    > ul {
        min-width: 250px;
    }

    li label, li .option-label {
        cursor: pointer;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    li.option-disabled label, li.option-disabled .option-label {
        cursor: default;
        color: $mediumGrayColor;
    }

    li > label, li > .option-label {
        margin-bottom: 0 !important;
    }
    &.stretch {
        .dropdown-toggle {
            .label-wrapper {
                width: 100%;
                display: table;
                .label-wrapper-inner {
                    display: table-cell;
                    max-width: 1px; // doesn't works without this trick
                }
            }
        }
    }

    .dropdown-toggle {
        padding-right: $grid-gutter-width * 3;
        position: relative;

        .label-wrapper {
            .label-wrapper-inner {
                .label-text-overflow {
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }
            }
        }

        .icon-wrapper {
            position: absolute;
            right: $grid-gutter-width;
            overflow: hidden;
            height: $line-height-computed;
        }
        &.btn-block {
            text-align: left;
        }
    }

    .dropdown-menu {
      &.stretch {
        width: auto;
      }
    }

    .multi-select-list-header {
        padding: $grid-gutter-width;
        background-color: $dropdown-filter-wrapper-bg-color;
        border-bottom: 1px solid $dropdown-filter-wrapper-border-color;
        margin: 0;
        > * {
            display: block;
            margin-bottom: $grid-gutter-width;
        }
        > .rc-filter {
          max-width: 230px;
        }
        > :last-child {
            margin-bottom: 0;
        }
        &:last-child {
            border-bottom: none;
        }
    }

    .multi-select-list-content {
        overflow-x: hidden;
        overflow-y: auto;
        max-height: 360px;
        padding: 4px;

        & .multi-select-group:first-child:last-child .multi-select-option:first-child:last-child label {
            border-bottom: 0px;
        }
    }

    .multi-select-filter {
        .form-group {
            margin: 0;
        }
    }

    .selected-option > .rc-icon {
        color: $primaryColor;
        float: left;
        margin-left: -1.5em;
    }

    .no-results {
        padding: $grid-gutter-width;
    }

    .show-more {
        display: block;
        padding: $grid-gutter-width;
        border-top: 1px solid $dropdown-filter-wrapper-border-color;
        cursor: pointer;
    }
}

.multi-select-option {
    padding-left: $grid-gutter-width;

    .checkbox {
        margin: 0;
    }

    .form-group {
        margin: 0;
    }

    label, .option-label {
        font-weight: normal;
        white-space: nowrap;
        display: block;
        padding-top: 8px;
        padding-bottom: 8px;
        padding-left: $default-padding;

        padding-right: $grid-gutter-width * 3;
        position: relative;

        .icon-wrapper {
            position: absolute;
            top: 8px;
            right: $grid-gutter-width;
        }
    }

    .select-description,.second-line {
        color: $mediumGrayColor;
    }

    &:hover {
        background-color: $lightestGrayColor;
    }
    &.option-disabled {
        &:hover {
            background-color: transparent;
        }
    }
}

.master-option {
  label, .option-label {
    padding-left: $default-padding;
  }
}

.multi-select-has-children {
  .master-option.multi-select-option-level-1 {
    label, .option-label {
      border-bottom: 1px solid $dropdown-filter-wrapper-border-color;
    }
  }
}

// First tree level paddings
.multi-select-group {
    .multi-select-option label, .multi-select-option .option-label {
        padding-left: $default-padding * 2;
    }

    .master-option {
        label {
            padding-left: $default-padding * 2;
        }
        &.option-disabled {
            label {
                border-bottom-color: $lightGrayColor;
            }
        }
    }

    // Second tree level
    .multi-select-group {
        .multi-select-option label, .multi-select-option .option-label {
            border-bottom: none;
            padding-left: $default-padding * 3;
        }

        .master-option label, .master-option .option-label {
            padding-left: $default-padding * 3;
        }

        // Third tree level
        .multi-select-group {
            .multi-select-option label, .multi-select-option .option-label {
                padding-left: $default-padding * 4;
            }

            .master-option label, .master-option .option-label {
                padding-left: $default-padding * 4;
            }

            // Fourth tree level
            .multi-select-group {
                .multi-select-option label, .multi-select-option .option-label {
                    padding-left: $default-padding * 5;
                }

                .master-option label, .master-option .option-label {
                    padding-left: $default-padding * 5;
                }

                // TODO: add more levels if needed
            }
        }
    }
}

.rc-toggle{
    input {
        position: absolute;
        clip: rect(0, 0, 0, 0);
    }
    .rc-toggle-input {
        width: 36px;
        height: $toggleHeight;
        border-radius: 100px;
        display: inline-block;
        vertical-align: bottom;
        margin-left: -$default-padding;
        &:not(:last-child) {
            margin-right: $grid-gutter-width/2;
        }

        .rc-toggle-circle {
            width: $toggleHeight - 2px;
            height: $toggleHeight - 2px;
            background-color: $whiteColor;
            border-radius: 100px;
            box-sizing: border-box;
        }

        &:hover:not(.rc-toggle-disabled){
            .rc-toggle-circle {
                background-color: $toggle-hover-enabled-color;
            }
        }
        &.rc-toggle-focus {
            .rc-toggle-circle {
                box-shadow:  0px 0px 2px 3px $customControlsOutline !important;
            }
        }

        &.rc-toggle-on {
            background-color: $toggle-on-color;
            border: 1px solid $toggle-on-color;

            &:hover:not(.rc-toggle-disabled){
                background-color: $toggle-on-hover-bg-color;
                border: 1px solid $toggle-on-hover-bg-color;
            }

            .rc-toggle-circle {
                margin-left: $toggleHeight - 4px;
            }
        }

        &.rc-toggle-off {
            background-color: $whiteColor;
            border: 1px solid $toggle-off-border-color;
            &:hover:not(.rc-toggle-disabled){
                background-color: $toggle-off-hover-bg-color;
            }
            .rc-toggle-circle {
                box-shadow: 0px 1px 2px 1px rgba(47,47,47,0.3);
            }
        }

        &.rc-toggle-disabled {
            opacity: 0.4;
        }
    }
}
