/*!
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

@use 'sass:map';
@use '@angular/material' as mat;

@mixin generate-codemirror-theme($material-theme, $config) {
    $is-material-dark: if(mat.get-theme-type($material-theme) == dark, true, false);
    $material-theme-secondary-palette-default: mat.get-theme-color(
        $material-theme,
        secondary,
        map.get(map.get($config, secondary), default)
    );
    $material-theme-tertiary-palette-variant: mat.get-theme-color(
        $material-theme,
        tertiary,
        map.get(map.get($config, tertiary), variant)
    );
    $material-theme-neutral-palette-default: mat.get-theme-color(
        $material-theme,
        neutral,
        map.get(map.get($config, neutral), default)
    );
    $material-theme-neutral-palette-darker: mat.get-theme-color(
        $material-theme,
        neutral,
        map.get(map.get($config, neutral), darker)
    );
    $material-theme-neutral-palette-lighter: mat.get-theme-color(
        $material-theme,
        neutral,
        map.get(map.get($config, neutral), lighter)
    );
    $primary-contrast: map.get(map.get($config, primary), contrast);
    $neutral-contrast: map.get(map.get($config, neutral), contrast);
    $border-color: mat.get-theme-color($material-theme, neutral-variant, map.get($config, neutral-variant));
    $selected-color: $material-theme-tertiary-palette-variant;

    .ngx-codemirror {
        display: none;
    }

    .cm-s-nifi.CodeMirror {
        @extend .neutral-contrast;
        height: 100%;
        cursor: default;
        line-height: normal;
        background-color: if(
            $is-material-dark,
            $material-theme-neutral-palette-darker,
            $material-theme-neutral-palette-lighter
        );
        border: 1px solid var(--mdc-outlined-text-field-label-text-color);
    }

    .cm-s-nifi .CodeMirror-gutters {
        background: if($is-material-dark, #3b3b3b, #efefef);
    }

    .cm-s-nifi .CodeMirror-guttermarker,
    .cm-s-nifi .CodeMirror-guttermarker-subtle,
    .cm-s-nifi .CodeMirror-linenumber {
        color: if($is-material-dark, #bbbbbb, #b4b4b4);
    }

    .cm-s-nifi .CodeMirror-cursor {
        border-left: 1px solid $neutral-contrast;
    }

    .cm-s-nifi div.CodeMirror-selected {
        background: $selected-color;
    }

    .cm-s-nifi.CodeMirror-focused div.CodeMirror-selected {
        background: $selected-color;
    }

    .cm-s-nifi .CodeMirror-line::selection,
    .cm-s-nifi .CodeMirror-line > span::selection,
    .cm-s-nifi .CodeMirror-line > span > span::selection {
        background: if($is-material-dark, rgba(128, 203, 196, 0.2), rgba(128, 203, 196, 0.8));
    }

    .cm-s-nifi .CodeMirror-line::-moz-selection,
    .cm-s-nifi .CodeMirror-line > span::-moz-selection,
    .cm-s-nifi .CodeMirror-line > span > span::-moz-selection {
        background: if($is-material-dark, rgba(128, 203, 196, 0.2), rgba(128, 203, 196, 0.8));
    }

    .cm-s-nifi .cm-header {
        color: if($is-material-dark, #b8b8ff, #0000ff);
    }

    .cm-s-nifi .cm-quote {
        color: if($is-material-dark, #6bfd6b, #009400);
    }

    .cm-s-nifi .cm-negative {
        color: if($is-material-dark, #fc9797, #de3535);
    }

    .cm-s-nifi .cm-positive {
        color: if($is-material-dark, #8cfd8c, #219a21);
    }

    .cm-s-nifi .cm-bracket {
        color: if($is-material-dark, #93937c, #93937c);
    }

    .cm-s-nifi .cm-link {
        color: if($is-material-dark, #8e8ef6, #0000ce);
    }

    .cm-s-nifi .cm-invalidchar {
        color: if($is-material-dark, #ff9c9c, #ff0000);
    }

    .cm-s-nifi .cm-keyword {
        color: if($is-material-dark, #c792ea, #6800ab);
    }

    .cm-s-nifi .cm-operator {
        color: if($is-material-dark, #89ddff, #0083b9);
    }

    .cm-s-nifi .cm-variable-2 {
        color: if($is-material-dark, #72b6fc, #0054a6);
    }

    .cm-s-nifi .cm-variable-3,
    .cm-s-nifi .cm-type {
        color: if($is-material-dark, #f07178, #ad0007);
    }

    .cm-s-nifi .cm-builtin {
        color: if($is-material-dark, #a280f3, #3400ad);
    }

    .cm-s-nifi .cm-atom {
        color: if($is-material-dark, #f78c6c, #bd2b00);
    }

    .cm-s-nifi .cm-number {
        color: if($is-material-dark, #fd758c, #c20021);
    }

    .cm-s-nifi .cm-def {
        color: if($is-material-dark, #82aaff, #0553f8);
    }

    .cm-s-nifi .cm-string {
        color: if($is-material-dark, #f07178, #ec000c);
    }

    .cm-s-nifi .cm-string-2 {
        color: if($is-material-dark, #f07178, #ec000c);
    }

    .cm-s-nifi .cm-comment {
        color: if($is-material-dark, #d7d7d7, #545454);
    }

    .cm-s-nifi .cm-variable,
    .cm-s-nifi .cm-punctuation,
    .cm-s-nifi .cm-property,
    .cm-s-nifi .cm-operator {
        color: if($is-material-dark, #fff, #000);
    }

    .cm-s-nifi .cm-tag {
        color: if($is-material-dark, #fc768d, #f8052e);
    }

    .cm-s-nifi .cm-meta {
        color: rgba($material-theme-secondary-palette-default, 0.87);
    }

    .cm-s-nifi .cm-attribute {
        color: if($is-material-dark, #c792ea, #8e01ea);
    }

    .cm-s-nifi .cm-property {
        color: if($is-material-dark, #c792ea, #8e01ea);
    }

    .cm-s-nifi .cm-qualifier {
        color: rgba($material-theme-secondary-palette-default, 0.87);
    }

    .cm-s-nifi .cm-variable-3,
    .cm-s-nifi .cm-s-default,
    .cm-s-nifi .cm-type {
        color: rgba($material-theme-secondary-palette-default, 0.87);
    }

    .cm-s-nifi .cm-error {
        color: if($is-material-dark, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0));
        background-color: if($is-material-dark, #ff002a, #ff8094);
    }

    .cm-s-nifi .CodeMirror-matchingbracket {
        text-decoration: underline;
        color: $primary-contrast !important;
        background-color: $material-theme-neutral-palette-default;
    }

    .cm-s-nifi .CodeMirror-nonmatchingbracket {
        color: if($is-material-dark, #fc7a7a, #a62020);
    }

    .cm-s-nifi .CodeMirror-matchingtag {
        background: if($is-material-dark, rgba(255, 150, 0, 0.97), rgba(255, 150, 0, 0.3));
    }

    .cm-s-nifi .CodeMirror-activeline-background {
        background: if($is-material-dark, rgba(255, 255, 255, 0.5), rgba(0, 0, 0, 0.5));
    }
}
