/**
 * Actions
 * --
 * A list of actions that the user can click which relate to the page the user
 * is currently on. These are displayed as buttons to the right of the heading.
 * In desktop view, up to X actions/buttons can be displayed. If more than X
 * are available, a dropdown option is provided to the right of the buttons.
 */


.mh-body--has-actions {
    .mh-frame {
        @include media-span($from: 0, $to: $tablet-landscape-width) {
            padding-bottom: $action-height !important;
        }
    }
}

@include media-span($from: 0, $to: $tablet-landscape-width) {

}

.mh-frame--prime-nav-open,
.mh-frame--user-nav-open {

    .mh-main__inner > .mh-heading .mh-actions {
        @include media-span($from: 0, $to: $tablet-landscape-width) {
            z-index: 10 !important;
        }
    }
}

.mh-actions {
    /**
     * Mobile
     * --
     * On mobile, heading actions are handled differently depending on whether
     * they are relative to the page, or specific to a single area of the page
     * and contained within a box. If they are page actions inside the main
     * heading, they get fixed to the bottom of the page. If they are specific
     * to a box, they are positioned to the top right hand side of the box and a
     * dropdown is used to view them.
     */
    @include media-span($from: 0, $to: $tablet-landscape-width) {

        /**
         * Actions inside of the main page heading on mobile
         */
        .mh-main__inner > .mh-heading & {
            background-color: $color-bkg-nav;
            box-shadow: 0 -1px 0 0 #fff;
            width: 100%;
            z-index: 15;
            transition: left 0.5s ease-in-out;
            @include position(fixed, null null 0px 0px);

            &--open {
                @for $i from 1 through $max-actions {
                    &.mh-actions--#{$i} {
                        .mh-actions__list {
                            height: calc((#{$action-height} * #{$i}) + 16px);
                        }
                    }
                }
            }

            &__handle {
                background-color: nth($color-themes, 1);
                box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
                cursor: pointer;
                display: block;
                height: $action-height;
                position: relative;

                &:hover {
                    box-shadow: inset 100vw 0 0 0 rgba(0, 0, 0, 0.075);
                }

                &-dots {
                    left: 50%;
                    margin: -2px 0 0 -2px;
                    top: 50%;

                    &, &:before, &:after {
                        background-color: #fff;
                        border-radius: 50%;
                        content: '';
                        display: block;
                        height: 4px;
                        position: absolute;
                        width: 4px;
                    }

                    &:before {
                        left: -200%;
                        top: 0;
                    }

                    &:after {
                        left: 200%;
                        top: 0;
                    }
                }
            }

            &__list {
                height: 0;
                overflow: hidden;
                transition: height 0.2s ease-in-out;
            }

            &__link {
                display: block;
                padding: 6px 20px;
                text-align: center;
                @include type(sub-nav, $color: $color-font-reverse);

                &:not(.mh-actions__link--disabled) {
                    &:hover, &:focus {
                        background-color: rgba(0, 0, 0, 0.1);
                        color: #fff;
                    }
                }

                &:first-child { margin-top: 8px; }
                &:last-child { margin-bottom: 8px; }

                &--disabled {
                    cursor: not-allowed;
                    opacity: 0.6;
                }
            }
        }

        /**
         * Actions inside of heading in boxes on mobile
         */
        .mh-main__box .mh-heading & {
            position: relative;
            display: flex;

            @for $count from 1 through $max-actions {
                &--#{$count} .mh-actions__handle {
                    display: block;

                    &:after {
                        height: ((#{$action-height} * $count) + 20px);
                    }
                }
            }

            &--open {
                .mh-actions__handle {
                    background-color: $color-bkg-nav !important;
                    box-shadow: none !important;

                    &:after { display: block; }

                    &-dots {
                        &, &:before, &:after {
                            background-color: #fff;
                        }
                    }
                }

                .mh-actions__link {
                    display: block;
                }
            }

            &__list {
                display: flex;
            }

            &__link {
                display: none;
                height: $action-height;
                padding: 0 20px;
                width: 140px;
                z-index: 3;
                @include ellipsis($width: 140px);
                @include position(absolute, null 0px null null);
                @include type(
                    sub-nav,
                    $color: $color-font-reverse,
                    $line-height: $action-height
                );

                @for $i from 1 through $max-actions {
                    &:nth-child(#{$i}) {
                        top: calc(#{$action-height} + 20px + ((#{$i} - 1) * #{$action-height}));

                        &:not(.mh-actions__link--disabled) {
                            &:hover, &:focus {
                                background-color: rgba(0, 0, 0, 0.1);
                                color: #fff;
                            }
                        }

                        &.mh-actions__link--disabled {
                            cursor: not-allowed;
                            opacity: 0.6;
                        }
                    }
                }
            }

            &__handle {
                margin-left: 10px !important; // Overide button styles
                overflow: visible !important; //Overide button styles
                position: relative;
                @include btn(
                    $display: none,
                    $size: small,
                    $type: bordered,
                    $height: $action-height,
                    $width: $action-height
                );

                &:after {
                    background-color: $color-bkg-nav;
                    box-shadow: 0 3px 1px -1px rgba(0, 0, 0, 0.15);
                    border-radius: $corner-radius;
                    content: '';
                    display: none;
                    width: 140px;
                    z-index: 2;
                    @include position(absolute, ($action-height + 10px) 0px null null);
                }

                &-dots {
                    position: absolute;
                    left: 50% !important; // Overide btn styles
                    margin: -2px 0 0 -2px !important; // Overide btn styles
                    top: 50% !important; // Overide btn styles

                    &, &:before, &:after {
                        background-color: nth($color-themes, 1);
                        border-radius: 50%;
                        content: '';
                        display: block;
                        height: 4px;
                        overflow: visible;
                        position: absolute;
                        width: 4px;
                        z-index: 100;
                    }

                    &:before {
                        left: -200%;
                        top: 0;
                    }

                    &:after {
                        left: 200%;
                        top: 0;
                    }
                }
            }
        }
    }


    /**
     * Tablet/Desktop
     * --
     * Actions are absolutely positioned to the top right hand side of the
     * heading on tablet/desktop devices. If the number of actions exceeds the
     * max-actions limit, then additional actions are positioned into a dropdown
     * list to the far right which the user can toggle to view or not. Due
     * to this, tablet/desktop styles are entirely separated from mobile.
     */
    @include media-tablet-landscape() {
        position: relative;
        display: flex;

        @for $count from 1 through $max-actions {
            @if $count > $visible-actions {
                &--#{$count} .mh-actions__handle {
                    display: block;

                    &:after {
                        height: (($action-height * ($count - $visible-actions)) + 20px);
                    }
                }
            }
        }

        &--open {
            .mh-actions__handle {
                background-color: $color-bkg-nav !important;
                box-shadow: none !important;

                &:after { display: block; }

                &-dots {
                    &, &:before, &:after {
                        background-color: #fff;
                    }
                }
            }

            .mh-actions__link {
                display: block;
            }
        }

        @for $i from 1 through $max-actions {
            @if ($visible-actions >= $i) {
                &--#{$i} {
                    .mh-actions__handle {
                        display: none !important;
                    }
                }
            }
        }

        &__list {
            display: flex;
        }

        &__link {
            display: none;
            height: $action-height;
            padding: 0 20px;
            width: 140px;
            z-index: 3;
            @include ellipsis($width: 140px);
            @include position(absolute, null 0px null null);
            @include type(
                sub-nav,
                $color: $color-font-reverse,
                $line-height: $action-height
            );

            @for $i from 1 through $max-actions {
                @if $i > $visible-actions {
                    &:nth-child(#{$i}) {
                        top: calc(50% - (#{$action-height} / 2));
                        margin-top: calc(#{$action-height} + 20px + ((#{$i} - 1) * #{$action-height}) - (#{$action-height} * #{$visible-actions});

                        &:not(.mh-actions__link--disabled) {
                            &:hover, &:focus {
                                background-color: rgba(0, 0, 0, 0.1);
                                color: #fff;
                            }
                        }

                        &.mh-actions__link--disabled {
                            cursor: not-allowed;
                            opacity: 0.6;
                        }
                    }
                }
            }

            @for $i from 1 through $visible-actions {
                &:nth-child(#{$i}) {
                    display: block;
                    margin-left: 10px !important; // Overide btn styles
                    position: static;
                    @include btn(
                        $type: standard,
                        $color: nth($color-themes, 1) #fff,
                        $size: small,
                        $height: $action-height,
                        $width: 120px
                    );

                    /**
                     * Loop through all of the btns and create custom classes
                     * for each colour and type.
                     */
                    @each $name, $btn in $btns {
                        &.mh-actions__link--#{$name} {
                            @include btn-type(
                                nth($btn, 2),
                                nth($btn, 1)
                            );
                        }
                    }
                }
            }
        }

        &__handle {
            box-shadow: inset 0 0 0 1px nth($color-themes, 1);
            margin-left: 10px !important; // Overide button styles
            overflow: visible !important; //Overide button styles
            position: relative;

            @include btn-default($display: none, $width: $action-height);
            @include btn-size($size: 'small', $height: $action-height);

            &:hover {
                &::before {
                    background-color: nth($color-themes, 1);
                    bottom: 0;
                    box-shadow: none;
                    content: '';
                    display: block;
                    left: 0;
                    opacity: 0.15;
                    position: absolute;
                    right: 0;
                    top: 0;
                }
            }

            &:active,
            &:focus, {
                box-shadow:
                    0 0 0 1px nth($color-themes, 1),
                    inset 0 3px 1px -1px rgba(0, 0, 0, 0.15);
            }

            &::after {
                background-color: $color-bkg-nav;
                border-radius: $corner-radius;
                content: '';
                display: none;
                width: 140px;
                z-index: 2;
                @include position(absolute, ($action-height + 10px) 0px null null);
            }

            &-dots {
                position: absolute;
                left: 50% !important; // Overide btn styles
                margin: -2px 0 0 -2px !important; // Overide btn styles
                top: 50% !important; // Overide btn styles

                &, &:before, &:after {
                    background-color: nth($color-themes, 1);
                    border-radius: 50%;
                    content: '';
                    display: block;
                    height: 4px;
                    overflow: visible;
                    position: absolute;
                    width: 4px;
                    z-index: 100;
                }

                &:before {
                    left: -200%;
                    top: 0;
                }

                &:after {
                    left: 200%;
                    top: 0;
                }
            }
        }
    }
}


/**
 * Sub-action menus for actions.
 */
.mh-actions {
    .mh-actions {

        &__link {

            &--has-sub-actions {
                cursor: pointer;
                overflow: unset;

                @include media-span($from: 0, $to: $tablet-landscape-width) {

                    &::after {
                        content: ' ...';
                    }

                }

                @include media-tablet-landscape() {
                    padding-right: 46px;
                    position: relative;

                    &::before {
                        border-left: 1px solid #fff;
                        content: '';
                        display: block;
                        height: 30px;
                        position: absolute;
                        right: 0px;
                        top: 3px;
                        width: 36px;
                    }

                    &::after {
                        border-left: 5px solid transparent;
                        border-right: 5px solid transparent;
                        border-top: 5px solid #fff;
                        content: '';
                        display: block;
                        position: absolute;
                        right: 13px;
                    }

                    &:active {
                        &::after {
                            transform: rotate(180deg);
                        }
                    }
                }
            }

            &--sub-actions-open {

                .mh-sub-actions {
                    display: flex;

                    @include media-tablet-landscape() {
                        display: block;
                    }
                }

                @include media-tablet-landscape() {
                    box-shadow:
                        inset 100vw 0 0 0 rgba(0, 0, 0, 0.075),
                        inset 0 2px 0 0 rgba(0, 0, 0, 0.15)
                        !important
                    ;
                    padding-top: 1px;

                    &::after {
                        transform: rotate(180deg);
                    }
                }
            }
        }
    }

    .mh-sub-actions {
        display: none;

        @include media-span($from: 0, $to: $tablet-landscape-width) {
            align-items: center;
            background: rgba(#000, 0.8);
            bottom: 0;
            flex-direction: column;
            justify-content: center;
            left: 0;
            pointer-events: none;
            position: fixed;
            right: 0;
            top: 0;
            z-index: 1;
        }

        @include media-tablet-landscape() {
            background: #fff;
            border-radius: 3px;
            box-shadow:
                0 2px 0 0 rgba(0, 0, 0, 0.1),
                inset 0 0 0 1px rgba(0, 0, 0, 0.2);
            height: auto;
            overflow: hidden;
            right: 0;
            position: absolute;
            top: 44px;
        }

        &__link {
            display: block;
            color: nth($color-themes, 1);
            max-width: 360px;
            pointer-events: auto;

            @include media-span($from: 0, $to: $tablet-landscape-width) {
                background: #fff;
                box-shadow: inset 0 1px 0 0 rgba(0, 0, 0, 0.1);
                font-size: 16px;
                height: 60px;
                line-height: 60px;
                width: calc(100% - 40px);

                &:first-child {
                    border-radius: 3px 3px 0 0;
                    box-shadow: none;
                }

                &:last-child {
                    border-radius: 0 0 3px 3px;
                }
            }

            @include media-tablet-landscape() {
                box-shadow: inset 0 1px 0 0 rgba(0, 0, 0, 0.1);
                height: 36px;
                line-height: 36px;
                overflow: hidden;
                padding: 0 20px;
                text-align: left;
                text-overflow: ellipsis;
                white-space: no-wrap;

                &:first-child {
                    box-shadow: none;
                }

                &:hover {
                    background: nth($color-themes, 1);
                    color: #fff;
                }
            }

            &--disabled {
                cursor: not-allowed;
                color: $color-font-lighter;

                &:hover {
                    background: none;
                    color: $color-font-lighter;
                }
            }
        }
    }
}
