// Page Layouts
$carded-header-height: 200px !default;
$carded-header-height-sm: 160px !default;
$carded-toolbar-height: 64px !default;

$header-height: 120px !default;
$header-height-sm: 100px !default;

// Calculate toolbarless header height
$carded-header-height-without-toolbar: $carded-header-height - $carded-toolbar-height;
$carded-header-height-without-toolbar-sm: $carded-header-height-sm - $carded-toolbar-height;

.page-layout {
    position: relative;
    overflow: hidden;

    // Carded layout

    &.carded {
        display: flex;
        flex-direction: row;
        width: 100%;
        height: 100%;
        min-width: 100%;
        min-height: 100%;

        // Top bg
        .top-bg {
            position: absolute;
            z-index: 1;
            top: 0;
            right: 0;
            left: 0;
            height: $carded-header-height;

            @include media-breakpoint('sm') {
                height: $carded-header-height-sm;
            }
        }

        // Fullwidth
        &.fullwidth {

            // Single scroll
            &.single-scroll {
                height: auto;

                > .center {

                    .content-card {

                        .content {
                            overflow: hidden;
                        }
                    }
                }
            }

            // Center
            > .center {
                display: flex;
                flex-direction: column;
                flex: 1;
                position: relative;
                z-index: 2;
                margin-left: 32px;
                margin-right: 32px;

                .header {
                    height: $carded-header-height-without-toolbar;
                    min-height: $carded-header-height-without-toolbar;
                    max-height: $carded-header-height-without-toolbar;

                    @include media-breakpoint('sm') {
                        height: $carded-header-height-without-toolbar-sm;
                        min-height: $carded-header-height-without-toolbar-sm;
                        max-height: $carded-header-height-without-toolbar-sm;
                    }
                }

                .content-card {
                    display: flex;
                    flex-direction: column;
                    flex: 1;
                    overflow: hidden;
                    background: mat-color($background, background);
                    @include mat-elevation(7);

                    .toolbar {
                        display: flex;
                        justify-content: flex-start;
                        align-items: center;
                        border-bottom: 1px solid rgba(0, 0, 0, 0.12);
                        height: $carded-toolbar-height;
                        min-height: $carded-toolbar-height;
                        max-height: $carded-toolbar-height;
                    }

                    .content {
                        display: flex;
                        flex: 1;
                        overflow: auto;
                        background: mat-color($background, background);
                    }
                }
            }
        }

        // Left sidenav - Right sidenav
        &.left-sidenav,
        &.right-sidenav {

            // Single scroll
            &.single-scroll {
                height: auto;
            }

            > md-sidenav-container {
                display: flex;
                background: none;
                z-index: 2;
                width: 100%;

                .sidenav {
                    display: flex;
                    flex-direction: column;
                    width: 240px;
                    min-width: 240px;
                    max-width: 240px;
                    z-index: 2;
                    overflow-y: hidden;
                    @include mat-elevation(7);

                    &.md-is-locked-open {
                        position: relative;
                        background: none;
                        box-shadow: none;
                    }

                    &.md-stop-transition {

                        ~ .mat-sidenav-content {
                            transition: none;
                        }
                    }

                    .header {
                        height: $carded-header-height;
                        min-height: $carded-header-height;
                        max-height: $carded-header-height;
                    }

                    .content {
                        background: transparent;
                        overflow: auto;
                    }
                }

                .mat-sidenav-content {
                    flex: 1;
                    overflow: visible;

                    // Center
                    .center {
                        display: flex;
                        flex-direction: column;
                        flex: 1;
                        position: relative;
                        z-index: 3;
                        height: 100%;
                        margin-left: 32px;
                        margin-right: 32px;

                        .header {
                            display: flex;
                            height: $carded-header-height-without-toolbar;
                            min-height: $carded-header-height-without-toolbar;
                            max-height: $carded-header-height-without-toolbar;
                        }

                        .content-card {
                            display: flex;
                            flex-direction: column;
                            flex: 1;
                            overflow: hidden;
                            background: mat-color($background, background);
                            @include mat-elevation(7);

                            .toolbar {
                                display: flex;
                                justify-content: flex-start;
                                align-items: center;
                                flex: 1;
                                border-bottom: 1px solid rgba(0, 0, 0, 0.12);
                                height: $carded-toolbar-height;
                                min-height: $carded-toolbar-height;
                                max-height: $carded-toolbar-height;

                                .sidenav-toggle {
                                    margin: 0 8px 0 0 !important;
                                    padding: 0 !important;
                                    border-radius: 0;
                                }
                            }

                            .content {
                                display: flex;
                                flex: 1;
                                background: mat-color($background, background);
                                overflow: auto;
                            }
                        }
                    }
                }
            }
        }

        // Left sidenav
        &.left-sidenav {

            // Sidenav
            > md-sidenav-container {

                .sidenav {

                    &.md-is-locked-open {

                        ~ .mat-sidenav-content {
                            margin-left: 0 !important;

                            .center {
                                margin-left: 0;
                            }
                        }
                    }
                }
            }
        }

        // Right sidenav
        &.right-sidenav {

            // Sidenav
            > md-sidenav-container {

                .sidenav {
                    order: 999;

                    &.md-is-locked-open {

                        ~ .mat-sidenav-content {
                            margin-right: 0px !important;

                            .center {
                                margin-right: 0;
                            }
                        }
                    }
                }
            }
        }
    }

    // Simple layout
    &.simple {

        // Top bg
        .top-bg {
            position: absolute;
            z-index: 1;
            top: 0;
            right: 0;
            left: 0;
            height: $header-height;
        }

        // Fullwidth
        &.fullwidth,
        &.inner-sidenav {
            min-height: 100%;

            > .header {
                height: $header-height;
                min-height: $header-height;
                max-height: $header-height;
            }
        }

        // Left sidenav - Right sidenav
        &.left-sidenav,
        &.right-sidenav {
            min-height: 100%;
            height: 100%;

            // Single scroll
            &.single-scroll {
                height: auto;

                > md-sidenav-container {

                    > .center {
                        overflow: hidden;
                    }
                }
            }

            // Inner Sidenav
            &.inner-sidenav {

                > md-sidenav-container {

                    .sidenav {

                        &.md-is-locked-open {
                            height: auto;
                        }
                    }

                    .mat-sidenav-content {
                        display: flex;
                        height: auto;

                        .center {
                            @include mat-elevation(0);

                            .content {
                                @include mat-elevation(4);
                            }
                        }
                    }
                }
            }

            > md-sidenav-container {
                display: flex;
                background: none;
                z-index: 2;
                width: 100%;

                .sidenav {
                    width: 240px;
                    min-width: 240px;
                    max-width: 240px;
                    z-index: 51;
                    @include mat-elevation(7);

                    &.md-is-locked-open {
                        width: 220px;
                        min-width: 220px;
                        max-width: 220px;
                        box-shadow: none;
                        background: transparent;
                    }

                    &.md-stop-transition {

                        ~ .mat-sidenav-content {
                            transition: none;
                        }
                    }
                }

                .mat-sidenav-content {
                    display: flex;
                    flex: 1;
                    overflow: visible;

                    .header {
                        height: $header-height;
                        min-height: $header-height;
                        max-height: $header-height;
                    }

                    .center {
                        overflow: auto;
                        @include mat-elevation(7);

                        .content {
                            background: mat-color($background, background);
                        }
                    }
                }
            }
        }

        // Tabbed
        &.tabbed {
            min-height: 100%;

            .header {
                height: $header-height;
                min-height: $header-height;
                max-height: $header-height;
            }

            > .content {

                .mat-tab-group {

                    .mat-tab-labels {
                        padding: 0 24px;
                    }
                }
            }
        }
    }

    // Blank layout
    &.blank {
        min-height: 100%;
    }
}
