// 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: 1;

    @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: theme('colors.gray.100');
    padding: theme('padding.4');
    color: theme('colors.gray.800');
    font-size: theme('fontSize.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;
    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: theme('colors.gray.100');

    @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: theme('padding.4');
    color: theme('colors.gray.600');
}

.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 theme('colors.gray.400');
    padding-left: theme('padding.4');
}

.tb-map-filter-item.is-selected {
    background-color: theme('colors.secondary.700');
    color: theme('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: theme('padding.4');
    padding-right: theme('padding.4');

    .c-icon {
        top: 0;
    }
}

.tb-map-filter-item__name {
    display: block;
    flex: 1;
    padding: theme('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: theme('padding.8');
}

.tb-map-filter-menu__action {
    background-color: theme('colors.gray.100');
    padding: theme('padding.4') theme('padding.3');

    @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: theme('colors.gray.100');
    }

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

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

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

    .tb-map-filter-menu__toggle {
        background-color: theme('colors.gray.100');
    }

    .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: theme('colors.gray.400');
        color: theme('colors.secondary.900');
    }

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

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

        .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: theme('padding.16');
        }

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

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

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

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

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

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