@charset "utf-8";
@use "../util";
@use "../base/choose";
@use "../base/colors";
@use "../base/icons";
@use "../base/lengths";
@use "../base/mixins";

/**
 * Virtual Collection Builder
 */

$left-padding: 4em;
$bracket-size: .4em;

// Rules for VC view (including fragments)
.vc {
  margin-top: 4pt;

  .builder {
    position: initial;

    + .action {
      .minimize::after {
        color: colors.$dark-grey !important;
      }
    }
  }

  .docGroup {
    position:    relative;
    display:     inline-block;
    margin-left: $left-padding;
    padding:     4pt 2pt 4pt 0pt;

    border: {
      radius: lengths.$standard-border-radius * 2;
      style:  solid;
      width:  0 $bracket-size;
    }

    .docGroup {
      display: block;
    }

    &[data-operation] {

      > .doc:first-child::before,
      > .docGroup:first-child::before {
        content: none;
      }

      > .doc::before,
      > .docGroup::before {
        position:    absolute;
        display:     inline-block;
        text-align:  right;
        width:       $left-padding;
        margin-left: -1 * ($left-padding + .5em);
        line-height: 1.5em;
        border-top:  lengths.$border-size solid transparent;
      }

      > .docGroup::before {
        margin-left: -1 * ($left-padding + .5em) + (-1 * $bracket-size);
      }
    }

    // Or operation
    &[data-operation=or] {
      > .doc::before,
      > .docGroup::before {
        // This will be overruled by JS!
        content: "or";
      }
    }

    // And operation
    &[data-operation=and] {
      > .doc::before,
      > .docGroup::before {
        // This will be overruled by JS!
        content: "and";
      }
    }


    /**
     * All operators on groups
     */
    > .operators {
      position:       absolute;
      display:        block;
      vertical-align: middle;
      top:            10px;
      left:           3px;
      margin-left:    100%;
      padding:        0;

      > span:first-child {
        border: {
          top-left-radius:    0;
          bottom-left-radius: 0;
        }
      }
    }
  }

  
  /**
   * All document rules
   */
  .doc {
    line-height: 170%;
    padding-left: $left-padding;

    > span {

      + span,
      + div + span,
      + ul + span {
        margin-left: 5pt;
      }

      &.key,
      &.value {
        font-weight: bold;
      }

      &.value[data-type=regex] {
        font-style: italic;

        &::after,
        &::before {
          content: '/';
        }
      }

      &.key {
        position: relative;

        > ul {
          margin:      0;
          margin-left: 3.3em;
        }

        &.fixed {
          color: colors.$light-green;
        }
      }
    }

    // Unspecified value
    &.unspecified > span,
    span.unspecified {
      @include choose.choose-item;
      padding:    0 4px;
      box-shadow: choose.$choose-box-shadow;

      border: {
        style:  solid;
        width:  lengths.$border-size;
        radius: lengths.$standard-border-radius;
      }
    }

    // All operators on docs
    > .operators {
      display:     inline-block;
      margin-left: 10px;
    }
  }

  .rewritten .rewrite {
    display:     inline-block;
    margin-left: 4pt;
    color:       colors.$dark-orange;
    &::after {
      @include mixins.icon-font;
      font-style:      normal;
      font-weight:     normal;
      content:         icons.$fa-rewrite;
      text-decoration: underline;
    }

    > span {
      display: none;
    }
  }

  /**
   * All operators
   */
  .operators {
    opacity:     0;
    white-space: nowrap;
    padding:     0;
    font-size:   0;
    line-height: 0;
    text-align:  center;
  }

  > .docGroup {
    margin-left: 0;
  }

  .menu {
    display: inline-block;
  }

  // referTo entries
  .menu li[data-type=ref]::before,
  span.key.ref::before {
    @include mixins.icon-font;
    content:       icons.$fa-referto;
    padding-right: 4pt;
    font: {
      style:  normal;
      weight: normal;
    }
  }  

  div.value {
    position:   absolute;
    display:    inline-block;
    min-width:  max-content;
    z-index:    8000;
    padding:    4pt;
    margin-top: -6pt;

    border: {
      radius: lengths.$standard-border-radius;
      width:  lengths.$border-size;
      style:  solid;
    }

    input {
      border-width: 0;
      outline-width: 0;
    }

    > div {
      @include choose.choose-item;
      display: inline-block;
      padding: 0 4pt;
      margin-left: 4pt;

      font: {
        size:  80%;
        style: italic;
      }

      border: {
        width:  lengths.$border-size;
        style:  solid;
        radius: lengths.$standard-border-radius;
      }
    }

    &.regex {
      > input {
        font-style: italic;
      }

      > div {
        @include choose.choose-active;
      }
    }
  }
}

/* Rules for vcs excluding fragments,
 * i.e. includingy dynamic changes.
 */
.vc:not(.fragment) {

  .docGroup,
  .doc {
    color: colors.$dark-grey;
  }
  
  /**
   * Rules for all docGroups
   */
  // Whiten on hover 
  .docGroup:hover {
    background-color: rgba(255,255,255,.3);
  }

  .doc > span:not(.fixed) {
    cursor: pointer;
    &:hover {
      color: colors.$dark-orange;
    }
  }

    // Unspecified value
  .doc.unspecified > span,
  span.unspecified {
    &:hover {
	    @include choose.choose-hover;
    }
  }
  
  .doc, .docGroup {
    &:hover > .operators {
      opacity: 1;
    }
  }

  .docGroup {
    &[data-operation] {
      > .doc::before,
      > .docGroup::before {
        color: colors.$dark-orange;
      }
    }
    &[data-operation=or] {
      border-color: colors.$dark-orange;
    }
  }

  div.value {
    @include choose.choose-item;
    box-shadow: choose.$choose-box-shadow;

    > div {
      cursor:  pointer;
      &:hover {
        @include choose.choose-hover;
      }
    }
  }
}


/**
 * The z-index cascade for groups.
 */
$dg-index : 30;
.docGroup {
  > .operators {
    z-index: $dg-index;
  }
  .docGroup {
    > .operators {
      z-index: $dg-index + 1;
    }
    .docGroup {
      > .operators {
        z-index: $dg-index + 2;
      }
      .docGroup {
        > .operators {
          z-index: $dg-index + 3;
        }
        .docGroup {
          > .operators {
            z-index: $dg-index + 4;
          }
          .docGroup {
            > .operators {
              z-index: $dg-index + 5;
            }
            .docGroup {
              > .operators {
                z-index: $dg-index + 6;
              }
            }
          }
        }
      }
    }
  }
}

.vc.fragment {
  > div > div.docGroup {
    margin-left: 0;
  }
  .doc {
    margin-right: 2em;
  }
}

#collection {
  line-height: 1em;
  border-radius: lengths.$standard-border-radius;
}

#vc-choose > span.rewritten::after {
  @include mixins.icon-font;
  color:           colors.$dark-orange;
  padding:         0;
  padding-left:    4px;
  content:         icons.$fa-rewrite;
  text-decoration: underline;
  font-style:      normal;
  font-weight:     normal;
}

div#vc-view {
  position:relative;

  > div.vc {
    display:          none;
    margin:           2em 0 .5em 0;
    border:           2px solid colors.$dark-green;
    background-color: colors.$nearly-white;

    &.active {
      display: block;
    }

    > div:first-child {
      padding: 1.3em;
    }
  }
}

div.panel.vcinfo {
  padding:          3pt 0pt 3pt 3pt;
  background-color: colors.$dark-green;

  div.button-group > span {
    box-shadow: none;
  }
}
