// magic number for filter menu width to ensure this width across projects
$tb-map-filter-menu-width: 340px;

/*
 *  NOTE:
 *  fixed breakpoint 600px is used for filter menu style
 *  (in JS the same value should be used for initially
 *  opening the menu only on desktop if the option is set)
 */

.tb-map-filter-menu {
    position: relative;
    height: 100%;
    white-space: nowrap;

    // Give it a higher z-index than the map itself.
    z-index: 9999;

    @media screen and (max-width: 600px) {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        pointer-events: none;

        &.is-target {
            pointer-events: auto;
        }
    }
}

.tb-map-filter-menu__toggle {
    cursor: pointer;
    display: block;
    position: absolute;
    background-color: config('colors.grey-lightest');
    padding: config('padding.4');
    color: config('colors.grey-darker');
    font-size: config('textSizes.lg');
    transition: opacity 200ms ease-in-out;
    top: 0;
    z-index: 2;
}

.tb-map-filter-menu__toggle--open {
    left: 0;
    pointer-events: visible;

    .c-icon + span {
        margin-left: .5ch;
    }

    .is-target & {
        opacity: 0;
        pointer-events: none;
    }
}

.tb-map-filter-menu__toggle--close {
    right: 0;
    opacity: 0;
    pointer-events: none;
    text-align: center;

    .is-target & {
        opacity: 1;
        pointer-events: auto;
    }
}

.tb-map-filter-menu__body {
    position: relative;
    z-index: 1;
    width: 0;
    height: 100%;
    overflow: hidden;
    transition: width 140ms ease-in-out;

    @media screen and (max-width: 600px) {
        flex: 1;
    }
}

.tb-map-filter-menu.is-target .tb-map-filter-menu__body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    width: $tb-map-filter-menu-width;
    background-color: config('colors.grey-lightest');

    @media screen and (max-width: 600px) {
        width: 100%;
    }
}

.tb-map-filter-menu__title,
.tb-map-filter-menu__items,
.tb-map-filter-menu__action {
    opacity: 0;
    transition-property: opacity;
    transition-duration: 0;
    transition-timing-function: ease;
}

// stylelint-disable-next-line selector-max-class
.tb-map-filter-menu.is-target .tb-map-filter-menu__title,
.tb-map-filter-menu.is-target .tb-map-filter-menu__items,
.tb-map-filter-menu.is-target .tb-map-filter-menu__action {
    opacity: 1;
    transition-delay: 200ms;
    transition-duration: 140ms;
}

// stylelint-disable-next-line selector-max-class
.tb-map-filter-menu.is-target.is-filter-selected .tb-map-filter-menu__action {
    transition-delay: 0;
}

.tb-map-filter-menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tb-map-filter-menu li {
    width: 100%;
    padding: 0;
    margin: 0;
}

.tb-map-filter-menu__header {
    position: relative;
    padding: config('padding.4');
    color: config('colors.grey-dark');
}

.tb-map-filter-menu__header h4 {
    margin: 0;
    padding: 0;
}

.tb-map-filter-item {
    display: flex;
    width: 100%;
    outline: 0;
    cursor: pointer;
    border-bottom: 1px solid config('colors.grey-light');
    padding-left: config('padding.4');
}

.tb-map-filter-item.is-selected {
    background-color: config('colors.secondary');
    color: config('colors.white');
}

.tb-map-filter-item__icon {
    display: flex;
    align-items: center;
    flex-grow: 0;
    flex-shrink: 0;
    position: relative;
    margin-right: 1ch;

    .c-icon,
    img {
        pointer-events: none;
        width: 1.5rem;
        height: 1.5rem;
        top: 0;
    }
}

.tb-map-filter-item__toggle-icon {
    display: flex;
    align-items: center;
    border-left: 1px solid inherit;
    padding-left: config('padding.4');
    padding-right: config('padding.4');

    .c-icon {
        top: 0;
    }
}

.tb-map-filter-item__name {
    display: block;
    flex: 1;
    padding: config('padding.3') 0;
}

.tb-map-filter-menu__sub-items {
    max-height: 0;
    overflow: hidden;
    transition-property: max-height;
    transition-duration: 120ms;
    // custom ease out when closing
    transition-timing-function: cubic-bezier(0, .75, .25, .75);

    &.is-target {
        max-height: 100em;
        transition-duration: 240ms;
        // custom ease in when opening
        transition-timing-function: cubic-bezier(1, 0, 1, .35);
    }
}

.tb-map-filter-menu__sub-items .tb-map-filter-item {
    padding-left: config('padding.8');
}

.tb-map-filter-menu__action {
    background-color: config('colors.grey-lightest');
    padding: config('padding.4') config('padding.3');
    z-index: 1;

    @media screen and (min-width: 601px) {
        display: none;
    }
}

.tb-map-filter-menu.is-target .tb-map-filter-menu__action {
    width: auto;
}

.tb-map-filter-menu__confirm-button {
    width: 100%;
}

.tb-map--alternative-menu-style {
    .tb-map-filter-menu__action,
    .tb-map-filter-menu__body {
        background-color: config('colors.grey-lightest');
    }

    .tb-map-filter-menu__title-topline {
        display: 'block';
        font-family: config('fonts.cursive');
        color: config('colors.secondary');
        line-height: 1;
    }

    .tb-map-filter-menu__title {
        color: config('colors.secondary-darkest');
    }

    // stylelint-disable-next-line selector-max-class
    .tb-map-filter-menu.is-target .tb-map-filter-menu__body {
        background-color: config('colors.grey-lightest');
        padding: config('padding.6');
    }

    .tb-map-filter-menu__toggle {
        background-color: config('colors.grey-lightest');
    }

    .tb-map-filter-menu__items {
        li:first-child {
            display: none;
        }

        // stylelint-disable-next-line selector-max-compound-selectors
        li:last-child .tb-map-filter-item {
            border-color: transparent;
        }
    }

    .tb-map-filter-item {
        border-bottom-style: dashed;
        border-bottom-width: 2px;
        border-bottom-color: config('colors.grey-light');
        color: config('colors.secondary-darkest');
    }

    .tb-map-filter-item.is-selected {
        background-color: transparent;
        color: config('colors.secondary');
    }

    @media screen and (min-width: 1020px) {
        .tb-map-filter-menu {
            width: 50%;
            background-color: config('colors.grey-lightest');
        }

        .tb-map-filter-menu__toggle {
            display: none;
        }

        .tb-map-filter-menu__title,
        .tb-map-filter-menu__items,
        .tb-map-filter-menu__action {
            opacity: 1;
            transition-delay: 200ms;
            transition-duration: 140ms;
        }

        // stylelint-disable-next-line selector-max-class
        .tb-map-filter-menu.is-target .tb-map-filter-menu__body,
        .tb-map-filter-menu__body {
            width: 100%;
            padding: config('padding.16');
        }

        .tb-map-filter-menu__items {
            margin-top: config('margin.8');
        }

        .tb-map-filter-menu__sub-items {
            margin-left: config('margin.6');
        }

        .tb-map-filter-menu__title-topline {
            font-size: config('textSizes.xl');
        }

        .tb-map-filter-menu__title {
            font-size: config('textSizes.3xl');
        }

        .tb-map-filter-item {
            padding-left: config('padding.8');
        }

        .tb-map-filter-item__name {
            padding: config('padding.6') 0;
            font-size: config('textSizes.xl');
            font-weight: bold;
        }
    }
}
