@use "../base/var";
@use "../base/color";
@use "../base/const";
@use "../base/text";

[part~="wy-core-editor"] {
  flex: 1 1 100%;
  display: flex;
  flex-direction: column;
}

[part~="wy-core-editor-message"] {
  margin-inline: var.default(--wy-padding-sm);
}

/** CODEMIRROR **/
[part~="wy-core-editor"] {
  .cm-editor {
    flex: 1 1 100%;
    background-color: color.token(--wy-surface-container-lowest);
    color: color.token(--wy-on-surface);
    border: var.default(--wy-input-border-width) solid transparent; //#{color.token(--wy-outline-variant)};
    caret-color: #{color.token(--wy-primary)};

    &:focus {
      border-color: #{color.token(--wy-primary)};
    }

    .cm-content {
      font-family:
        #{var.default(--wy-input-font-family)},
        inherit;
      font-size: var.default(--wy-input-font-size);
      // No vertical padding here: CodeMirror maps clicks in it to the start or end of the document.
      padding: 0 var.default(--wy-input-padding-x);
    }
  }
}

[part~="wy-core-editor-line"],
[part~="wy-core-editor-multiline"] {
  .cm-editor {
    .cm-line:first-child {
      padding-top: var.default(--wy-input-padding-y);
    }

    .cm-line:last-child {
      padding-bottom: var.default(--wy-input-padding-y);
    }
  }
}

[part~="wy-core-editor-tooltips"] {
  width: 0;
  height: 0;
  position: fixed;

  z-index: const.$zindex-dropdown;

  border: none;
  padding: 0;

  overflow: visible;

  // Legacy mode used together with [hidden] attribute
  &:not([popover]) {
    display: block;
  }
}

[part~="wy-core-editor-multiline"] {
  .cm-editor {
    min-height: 4em;
    border-radius: var.default(--wy-border-radius);
    max-height: 11.25em;

    .cm-line {
      padding: 0;
    }
  }
}

[part~="wy-core-editor-line"] {
  align-self: center;

  .cm-editor {
    border-radius: var.default(--wy-input-filled-border-radius);
    max-height: 11.25em;

    &.cm-focused {
      border-color: #{color.token(--wy-outline-variant)};
    }

    .cm-content {
      font-size: var.default(--wy-input-font-size);

      min-height: calc(
        var.default(--wy-input-font-size) * var.wy-rem(1.5) + var.default(--wy-input-padding-y) * 2 -
          #{var.default(--wy-input-border-width)}
      );
      // `normal` fits any font's text boxes; when rows overlap, CodeMirror shows the cursor at a wrap on the next row.
      line-height: normal;
    }
  }
}

[part~="wy-core-editor-full"] {
  .cm-editor {
    min-height: 100%;
    border-radius: 0;
    border: none;
    background: none;
    color: inherit;

    .cm-line {
      word-break: break-word;
      white-space: pre-wrap;
      //font-family: var.default(--wy-font-monospace);
    }

    .cm-content {
      font-family: inherit;
      font-size: inherit;
      line-height: normal;
      padding: 0;
    }

    .cm-line {
      padding: 0;
    }
  }
}