@import '../../../wagtailblock/scss/helpers';


.page-editor {
    .content-wrapper {
        margin-bottom: 10em;
    }

    .breadcrumb {
        margin: -1.2em 0 2em;  // sass linter complains about $desktop-nice-padding here because of unit mismatch
        margin-left: -$desktop-nice-padding;
        margin-right: -$desktop-nice-padding;
        padding-left: calc(#{$desktop-nice-padding} - 2em);

        @include media-breakpoint-up(sm) {
            margin-top: -1.8em;
        }
    }

    .modal .breadcrumb {
        margin: 0;
        background-color: transparent;

        a {
            color: $color-grey-2;
        }

        li:hover {
            background-color: $color-grey-4;
        }

        .home {
            padding-left: 0;
        }
    }

    h1 {
        font-size: 1.915em;  // approximately 26px

        &.header-title {
            text-transform: initial;
        }
    }

    .header-title {
        padding-left: 0;
    }

    .modal-body .header-title h1 {
        font-size: 1.5em;
    }

    .header-meta {
        list-style: none;
        margin-top: 0;
        margin-bottom: 0;
        padding: 0;

        li {
            border: 0;
            float: left;
            height: 1.5em;
            line-height: 2em;
            margin: 1em 0.75em 1.5em 0;

            .icon {
                @include svg-icon(1.25em, text-bottom);

                margin-right: 0.2em;
            }

            .icon-warning {
                @include svg-icon();
            }

            &:first-child .button {
                margin-left: -0.8em;
            }

            .avatar {
                margin-left: 0;
            }
        }

        .button {
            font-size: 1em;
            font-weight: 600;
            margin-top: -0.25em; // Account for the button border
            overflow: initial;
            height: 2.5em;
            line-height: 2.5em;
        }

        .action-workflow-status {
            font-weight: 600;

            span {
                font-weight: 300;
            }
        }

        .human-readable-date {
            display: inline;
        }

        &--status {
            padding-right: 0.8em;
        }

        &--type {
            padding: 0 0.8em;
        }
    }

}

// An object is the basic wrapper around any field or group of fields in the editor interface
.object {
    @include nice-padding();
    position: relative;

    &:first-child {
        border: 0;
    }

    &.focused {
        border-color: $color-input-focus-border;
    }

    fieldset,
    .field-row {
        padding-top: $object-title-height + 12px;
    }

    fieldset {
        padding-left: 0;
        padding-right: 0;

        .field-row {
            padding-top: 0;
        }
    }

    .object-help {
        display: block;
        position: relative;
        z-index: 1;
        top: $object-title-height;
        margin-top: 0;
        padding-top: 1em;
        padding-right: $grid-gutter-width / 2;
        padding-left: 3em;
        opacity: 1;

        .icon-help {
            margin-left: -1.75em;
        }
    }

    &:hover .object-help {
        opacity: 1;
    }

    > .title-wrapper {
        box-sizing: border-box;
        height: $object-title-height;
        -webkit-font-smoothing: auto;
        background: $color-secondary-light;
        color: #200200;
        text-transform: uppercase;
        padding: 0.9em 0 0.9em 5em;
        font-size: 0.95em;
        margin: 0;
        line-height: 1.5em;
        font-weight: normal;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1;
        overflow: hidden;

        label {
            display: inline;
            text-transform: inherit;
            font-weight: inherit;
            float: none;
            width: auto;
            color: inherit;
            font-size: inherit;
        }

        &:before {
            @include font-smoothing;
            text-shadow: none;
            font-family: wagtail;
            text-transform: none;
            content: map-get($icons, 'arrow-down');
            text-align: center;
            display: block;
            position: absolute;
            z-index: 2;
            font-size: 2em;
            top: 0;
            line-height: 1.8em;
            left: 0;
            width: $desktop-nice-padding;
            color: $color-white;
            padding: 0;
            margin: 0;
            background-color: $color-secondary;
        }
    }

    .halloeditor {
        padding-top: 1em; // to provide space for editor buttons
        padding-bottom: 1em;

        &.expanded {
            padding-top: 5em; // to provide space for editor buttons
            padding-bottom: 2em;
        }

    }

    &.required {
        > .title-wrapper label:after {
            content: '*';
            color: $color-danger;
            font-weight: bold;
            display: inline-block;
            margin-left: 0.5em;
            line-height: 1em;
            font-size: 13px;
        }
    }

    // Special full-width, one-off fields i.e a single text or textarea input
    &.full {
        fieldset {
            display: block;
            float: none;
        }

        li {
            padding: 0;
        }

        .halloeditor {
            padding-top: 3em; // to provide space for editor buttons
            padding-bottom: 3em;

            &.expanded {
                padding-top: 5em; // to provide space for editor buttons
                padding-bottom: 5em;
            }
        }

        .error-message {
            @include nice-padding();
            padding-bottom: 2em;
        }

        .error,
        .error input:not([type=submit]),
        .error textarea,
        .error .halloeditor {
            background-color: $color-input-error-bg;
        }
    }

    // cursory styling for streamfield. Main styling in client/src/components/StreamField/StreamField.scss
    &.stream-field {
        background-color: #f6f6f6;
        padding-left: 20px;
        padding-right: 20px;

        &.required .field > label:after {
            display: none;
        }

        .object-layout_big-part {
            max-width: 100%;
        }

        fieldset {
            padding-bottom: 0;
            max-width: unset;
            // Workaround to make sure blocks do not overflow horizontally.
            min-width: 0;
        }

        .block_field > .field-content {
            width: 100%;
        }
    }

    // special panel for the publishing fields, requires a bit more pizzazz
    &.publishing {
        > .title-wrapper:before {
            content: map-get($icons, 'date');
            font-size: 1.8rem;
            line-height: 1.4em;
            width: 1.4em;
        }
    }

    &.privacy {
        > .title-wrapper:before {
            content: map-get($icons, 'view');
        }
    }

    .multiple {
        padding: 4.5em 0 0;

        fieldset {
            padding-top: 0;
            padding-bottom: 0;
        }
    }

    .fields {
        max-width: 100%;
    }

    // removes top padding from multiples used within another panel
    .fields .multiple {
        padding-top: 0;
    }

    .add {
        padding-top: 1em;
    }

    &.empty {
        border-bottom: 1px solid $color-white;

        > h3 {
            margin: 0;
            border-bottom: 1px solid $color-white;
        }

        // wrapper around add button for mutliple objects. Default version is wordless plus button for contracted groups of fields
        .add {
            @include transition(background-color 0.2s ease);
            position: relative;
            z-index: 2;
            top: 0;
            left: 0;
            width: 3.3em;
            padding: 0;
            margin: 0 0 0 -20px;
            cursor: pointer;

            .button {
                border-radius: 0;
                overflow: visible;
                background-color: $color-secondary-light;
                font-size: 0; // helps fake the effect of t.ext-replace class, which can't be used here.
                width: 2em;

                // stylelint-disable max-nesting-depth
                &:before {
                    position: relative;
                    padding: 0;
                    line-height: 1.8em; // specific height required as parent 'a' has no height
                    font-size: 1.4rem;
                    width: 1.8em;
                    background-color: $color-secondary;
                }

                &:hover:before {
                    background-color: darken($color-secondary, 5%);
                }
            }
        }

        .multiple {
            padding: 0;
        }
    }

    &.collapsible {
        // li.collapsed gets its height from the fieldset only, which is now hidden
        // and h2 has position: absolute which doesn't add to it either, so it would be 0 without this
        min-height: 41px;

        .title-wrapper {
            &:before {
                content: map-get($icons, 'collapse-up');
                cursor: pointer;
            }
        }

        &.collapsed {
            .title-wrapper {
                &:before {
                    content: map-get($icons, 'collapse-down');
                }
            }
        }
    }
}

// Custom styles that make some fields look more important
.full {
    input:not([type=submit]),
    textarea,
    .halloeditor {
        @include nice-padding;
        border-radius: 0;
        padding-top: 1.5em;
        padding-bottom: 1.5em;
        font-size: 1.2em;
        line-height: 1.6em;
    }
}

.title {
    input:not([type=submit]),
    textarea,
    .halloeditor {
        font-size: 2em;
        font-family: $font-serif;
    }
}

// Footer control bar for perfoming actions on the page
footer .actions {
    .button {
        font-weight: 600;
        text-overflow: ellipsis;
    }
}

footer .preview {
    button,
    .button {
        padding: 0 1em;

        .icon {
            margin-right: 0.5em;
        }

        @include media-breakpoint-down(xs) {
            width: 100%;
            margin-top: 2px;
            margin-bottom: 2px;
            height: 3em;
        }

        background-color: lighten($color-grey-2, 10%);
        border-color: lighten($color-grey-2, 10%);

        &:hover {
            background-color: $color-grey-2;
            border-color: $color-grey-2;
        }
    }

    .dropdown {
        input[type=button],
        input[type=submit],
        button,
        .button {
            background-color: lighten($color-grey-2, 10%);
            border-color: lighten($color-grey-2, 10%);

            &:hover {
                background-color: $color-grey-2;
                border-color: $color-grey-2;
            }
        }

        ul,
        .dropdown-toggle {
            background-color: lighten($color-grey-2, 10%);
        }

        .dropdown-toggle:hover,
        &.open > .button + .dropdown-toggle {
            background-color: $color-grey-2;
        }
    }
}

@include media-breakpoint-up(sm) {
    .object {
        fieldset {
            // Override column mixin for column items.
            display: block;
            // Override column mixin for column items.
            float: none;
            max-width: 1024px;
            padding-left: 0;
            padding-right: 0;

            fieldset {
                width: 100%;
            }
        }

        .object-layout {
            display: flex;
            flex-flow: row-reverse wrap;

            &_small-part {
                // IE11 requires units on the flex basis. Unitless breaks.
                // stylelint-disable-next-line length-zero-no-unit
                flex: 1 0 0%;
            }

            &_big-part {
                // IE11 requires units on the flex basis. Unitless breaks.
                // stylelint-disable-next-line length-zero-no-unit
                flex: 5 0 0%;
            }
        }

        .object-help {
            padding-bottom: 40px;
            margin-left: 10px;
            opacity: 0;
        }

        &.stream-field {
            .object-help {
                padding-left: 6.4em;
            }
        }

        &.full {
            fieldset {
                // Override column mixin for column items.
                display: block;
                // Override column mixin for column items.
                float: none;
                margin-left: -51px;
                padding: 0;
                padding-top: $object-title-height;
            }

            input:not([type=submit]),
            textarea,
            .halloeditor {
                border-width: 0 1px;
            }

            .field {
                padding: 0;
            }

            .field-content {
                display: block;
                float: none;
                width: auto;
                padding: inherit;
            }
        }

        .multiple {
            @include column(10);
            padding-left: 0;
            padding-right: 0;
        }

        &.empty .add {
            margin: 0 0 0 -50px;
        }
    }
}

.button.button--live {
    background-color: $color-white;
    color: $theme-color;
    border-radius: 2px;
    font-size: 14px;
    font-weight: 600;
    line-height: 2.3em;
    padding: 0 0.75em;

    .icon {
        @include svg-icon(1.25em);
        margin-right: 0.25em;
    }

    &:hover {
        background-color: $theme-color-darker;
        color: $color-white;
    }
}

.workflow-timeline {
    list-style: none;
    padding: 0;

    li {
        margin-bottom: 1.25em;
        position: relative;
    }

    li:not(:last-child)::after {
        content: '';
        color: $color-grey-3;
        position: absolute;
        top: 1.5em;
        left: calc(0.75em - 1px);
        height: 100%;
        border-left: 2px dotted;
    }

    .icon {
        fill: $color-grey-3;
    }

    .in_progress {
        font-weight: 700;

        .icon {
            fill: $color-text-base;
        }
    }

    .approved .icon {
        fill: $theme-color;
    }

    .needs_changes .icon,
    .rejected .icon {
        fill: $color-warning;
    }

    .cancelled .icon {
        fill: $color-danger-dark;
    }
}
