// To be used for opaque elements overlaid atop the selected row
$treeview_selection_opaque: gtkmix(currentColor, $view_bg_color, 10%);
$treeview_borders_opaque: gtkmix(currentColor, $view_bg_color, if($contrast == 'high', 40%, 20%));

treeview.view {
  border-left-color: $treeview_borders_opaque; // this is actually the tree lines color,
  border-top-color: $treeview_borders_opaque; // while this is the grid lines color, better then nothing
}

columnview.view,
treeview.view {
  @include focus-ring();

  &:selected {
    &:focus, & {
      border-radius: 0;
    }
  }

  &.separator {
    min-height: 2px;
    color: $border_color;
  }

  &:drop(active) {
    box-shadow: none;
  }

  > dndtarget:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: $drop_target_color;

    &.after { border-top-style: none; }

    &.before { border-bottom-style: none; }
  }

  &.expander {
    // GtkTreeView uses the larger of the expander’s min-width and min-height
    min-width: 16px;
    min-height: 16px;
    -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');

    &:dir(rtl) { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic-rtl'); }

    color: gtkalpha(currentColor, .7);

    &:hover, &:active { color: currentColor; }

    &:checked { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }

    &:disabled { color: gtkalpha(currentColor, $disabled_opacity); }
  }

  &.progressbar { // progress bar in treeviews
    &, &:selected {
      background-color: $accent_bg_color;
      color: $accent_fg_color;
    }

    box-shadow: none;
  }

  &.trough { // progress bar trough in treeviews
    background-color: gtkalpha(currentColor, 0.1);
  }

  > header {
    > button {
      @extend %undecorated_button;
      padding-top: 3px;
      padding-bottom: 3px;
      border-radius: 0;
      box-shadow: none;
      line-height: 100%;

      > box {
        color: gtkalpha(currentColor, if($contrast == 'high', .6, .4));
        font-weight: 700;
        font-size: 9pt;
        border-spacing: 6px;
      }

      &:hover > box {
        color: gtkalpha(currentColor, if($contrast == 'high', .9, .7));
        box-shadow: none;
      }

      &:active > box {
        color: currentColor;
      }

      sort-indicator {
        &.ascending {
          -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
        }
        &.descending {
          -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
        }

        min-height: 16px;
        min-width: 16px;
      }
    }
  }

  button.dnd,
  header.button.dnd { // for treeview-like derive widgets
    &:active, &:selected, &:hover, & {
      color: $accent_fg_color;
      background-color: $accent_bg_color;
      transition: none;
    }
  }

  acceleditor > label {
    // see tests/testaccel in GTK to test
    background-color: $treeview_selection_opaque;
  }
}

treeview.view > header > button {
  padding-left: 4px;
  padding-right: 4px;
  border-bottom: 1px solid $border_color;
}

/********************************************************
 * Data Tables                                          *
 * treeview like tables with individual focusable cells *
 * https://gitlab.gnome.org/GNOME/gtk/-/issues/2929     *
 ********************************************************/

columnview {
  // move padding to child cells
  > listview > row {
    padding: 0;

    // align horizontal sizing with header buttons
    > cell {
      padding: 8px 6px;

      &:not(:first-child) {
        border-left: 1px solid transparent;
      }
    }
  }

  > header > button {
    padding-left: 6px;
    padding-right: 6px;
    border-left: 1px solid transparent;

    &:first-child {
      border-left-width: 0;
    }
  }

  // make column separators visible when :show-column-separators is true
  &.column-separators {
    > listview > row > cell,
    > header > button {
      border-left-color: $border_color;
    }
  }

  > listview:not(.horizontal).separators > row:not(.separator) {
    border-top: 1px solid $border_color;
    border-bottom: none;
  }

  // shrink vertically for .data-table
  &.data-table > listview > row > cell {
    padding-top: 2px;
    padding-bottom: 2px;
  }

  ~ undershoot.top {
    box-shadow: inset 0 1px $border_color;
  }
}

columnview row:not(:selected) cell editablelabel:not(.editing):focus-within {
  outline: 2px solid $focus_border_color;
}

columnview row:not(:selected) cell editablelabel.editing:focus-within {
  outline: 2px solid $accent_color;
}

treeexpander {
  border-spacing: 4px;
}
