
//  icc-light-theme
$icc-themes: ();
$icc-current-theme: ();

@import '~@angular/material/theming.scss';
@include mat-core();

.orange {
  color: orange;
}

.green {
  color: green;
}

.blue {
  color: blue;
}

.icc-flex {
  flex: 1;
}


.icc-theme-light {
  $primary: mat-palette($mat-indigo);
  $accent:  mat-palette($mat-pink, A200, A100, A400);
  $warn:    mat-palette($mat-red);
  $theme:   mat-light-theme($primary, $accent, $warn);
  @include angular-material-theme($theme);
}


.icc-theme-dark {
  $primary: mat-palette($mat-blue-grey);
  $accent:  mat-palette($mat-amber, A200, A100, A400);
  $warn:    mat-palette($mat-deep-orange);
  $theme:   mat-dark-theme($primary, $accent, $warn);
  @include angular-material-theme($theme);
  .mat-table, .mat-drawer {
    background: #303030 !important;
  }
}



$icc-mapping: (
  checkbox-background-color: transparent,
  background-basic-color: green
);


@function icc-add-theme($theme, $name) {
  $theme: map-merge($icc-mapping, $theme);
  $new: ($name: $theme);
  $icc-themes: map-merge($icc-themes, $new) !global;
  @return $icc-themes;
}

@function icc-theme($key) {
  $value: map-get($icc-current-theme, $key);
  @if ($value == null) {
    @warn 'Theme: icc-theme cannot find value for key `' + $key +'`';
  }
  @return $value;
}

@function icc-get-key-value($theme, $key, $value) {
  $parent: map-get($theme, $value);
  @if ($parent != null) {
    @return icc-get-key-value($theme, $value, $parent);
  }
  @return $value;
}

@function icc-get-current-theme($theme-name, $theme) {
  $current-theme: ();
  @each $key, $value in $theme {
    $new: ($key: icc-get-key-value($theme, $key, $value));
    $current-theme: map-merge($current-theme, $new);
  }
  @return $current-theme;
}

@mixin icc-setup-current-context($theme-name, $theme) {
  $icc-current-theme: icc-get-current-theme($theme-name, $theme) !global;
}

@mixin icc-setup-scss-vars() {
  @each $theme-name, $theme in $icc-themes {
    @include icc-setup-current-context($theme-name, $theme);
    .icc-theme-#{$theme-name} {
      @content;
    }
  }
}

@mixin icc-configure-theme() {
  @include icc-setup-scss-vars() {
    @content;
  }
}

$theme: (
  icc-table-cell-border-color: rgba(0,0,0,.12),
  icc-background-color: #ffffff,
  icc-text-color: #000000,
  icc-menu-background-color: #e0e0e0,
  icc-portal-background-color: #e0e0e0,


  backgroundColor: #CCC,
  textColor: #0488e0,

  color-primary-100: #f2f6ff,

  color-basic-100: #ffffff,
  color-basic-200: #fbfbfb,

  background-basic-color-1: color-basic-100,
  background-basic-color-2: color-basic-200,
  background-basic-color: green
);

$icc-themes: icc-add-theme($theme, light);
$theme: (
  icc-table-cell-border-color: rgba(255, 255, 255, 0.12),
  icc-background-color: #303030,
  icc-text-color: #ffffff,
  icc-menu-background-color: #1f1f1f,
  icc-portal-background-color: #1f1f1f,




  backgroundColor: #000,
  textColor: #ddd,

  color-primary-100: #f2f6ff,
  color-basic-100: #0f0f0f,
  color-basic-200: #191919,
// background-color: #303030;
  background-basic-color-1: color-basic-100,
  background-basic-color-2: color-basic-200,
  background-basic-color: red
);

$icc-themes: icc-add-theme($theme, dark);



@mixin cdk-table-progress {
  .cdk-header-row.progress {
    border: none;
    min-height: 0;
    .cdk-header-cell {
      border: 0;
      padding: 0;
    }
    mat-progress-bar {
      bottom: 0;
      position: absolute;
      transition: height 0.3s, opacity 0.25s linear;
      &:not(.show) {
        height: 0;
        opacity: 0;
      }
    }
  }
}
@include cdk-table-progress;

.cdk-drag-preview {
  box-sizing: border-box;
  border-radius: 4px;
  background: #ccc;
  border: dotted 3px orangered;;
  box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
              0 8px 10px 1px rgba(0, 0, 0, 0.14),
              0 3px 14px 2px rgba(0, 0, 0, 0.12);
}

.cdk-drag-placeholder {
  opacity: 0;
  border: dotted 3px #999;
  box-sizing: border-box;
  background: #ccc;
  transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}

.cdk-drag-animating {
  transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}

@mixin table-header-component-theme() {
  .icc-cdk-table-header {
    $border-color: icc-theme(icc-table-cell-border-color);

    position: relative;
    .icc-cdk-table-header-row {
      display: flex;
      align-items: center;
    }

    .icc-cdk-table-header-filter-row {
      display: flex;
      align-items: center;
    }

    .icc-table-header-first-row-cell {
      border-bottom: 1px solid $border-color;
    }

    .icc-cdk-table-header-cell, .icc-cdk-table-filter-cell {
      text-align: center; // TODO configurable
      // border-top: 1px solid $border-color;
      border-bottom: 1px solid $border-color;
      border-right: 1px solid $border-color;
      // width: 100% // no need here
    }

    .icc-cdk-table-header-cell {
      height: 40px; // TODO configurable
      cursor: col-resize;
      // padding: 0px 10px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .icc-cdk-table-filter-cell {
      height: 32px; // TODO configurable
      // padding: 0px 10px;
    }

    .icc-cdk-table-filter-field {
      width: 100%
    }

    .icc-cdk-table-header-cell:first-child, .icc-cdk-table-filter-cell:first-child {
      border-left: 1px solid $border-color;
    }

    .icc-cdk-table-header-title {
      display: flex;
      cursor: pointer;
      width: 100%
    }

    .icc-cdk-table-header-sort {
      width: 100%;
      // padding-right: 20px; // no need for this
      box-sizing: border-box;
      white-space: nowrap; // this will support text ellipsis
      -ms-text-overflow: ellipsis;
      text-overflow: ellipsis;
      overflow: hidden;
      height: 100%;
    }

    /*
    .icc-cdk-table-filter-selection {
      display: flex;
      width: 100%;
    }

    .icc-cdk-table-row-selection-checkbox {
      // padding: 0px 5px;
      display: flex;
      width: 100%;
      justify-content: center;
    } */
  }
}



::ng-deep .cdk-virtual-scroll-content-wrapper { // need this to have horizonital scroll bar
  contain: unset !important;
}

.icc-cdk-table-data-row {
  display: flex;
  // align-items: center;
}

@mixin table-view-component-theme() {
  $border-color: icc-theme(icc-table-cell-border-color);
  .icc-cdk-table-data-cell {
    height: 30px; // TODO configurable
    border-bottom: 1px solid $border-color;
    border-right: 1px solid $border-color;
    // padding: 0px 10px; // no padding at cell level
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .icc-cdk-table-data-cell:first-child {
    border-left: 1px solid $border-color;
  }

  .icc-table-row-group {
    flex: 0 0 100%;
    justify-content: left;
    border-bottom: 1px solid $border-color;
    display: block;
  }
}

.icc-table-row-group-level2 {
  margin-left: 15px;
}

.icc-table-row-group-level3 {
  margin-left: 30px;
}



cdk-tree-node, cdk-nested-tree-node {
  display: block;
}

@mixin tree-view-component-theme() {
  $border-color: icc-theme(icc-table-cell-border-color);
  .icc-tree-node, .icc-table-column {
    display: inline-block; // TODO need inline block here, but the text is not valign in the cell
    height: 30px;
    border-bottom: 1px solid $border-color;
    border-right: 1px solid $border-color;
    text-align: center;
  }

  /*
  .icc-table-column {
      display: flex;
      align-items: center;
      justify-content: center;
  } */

  .icc-tree-node {
    border-left: 1px solid $border-color;
  }

  // for drag and drop
  .icc-tree-node {
    // background-color: rgb(66, 157, 253);
    // color: white;
    user-select: none;
    cursor: move;
    text-align: left;

    // &.cdk-drag-preview { // while dragging
      // @include mat-elevation(12);
    // }

    &.cdk-drag-placeholder { // potential drop area
      opacity: 0;
    }
  }

  // items moving away to make room for drop
  .cdk-drop-list-dragging .mat-tree-node:not(.cdk-drag-placeholder) {
    transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
  }
  // item being dropped
  .cdk-drag-animating {
    transition: transform 200ms cubic-bezier(0, 0, 0.2, 1);
  }

  .icc-tree-drop-inside {
    background-color: orange;
    opacity: 0.4;
  }

  .icc-tree-drop-before {
    border-top: 5px solid #00f;
    margin-top: 5px;
  }

  .icc-tree-drop-after {
    border-bottom: 5px solid red;
    margin-bottom: 5px;
  }
}




@mixin menu-component-theme() {
  .mat-menu-panel {
    background-color: icc-theme(icc-menu-background-color);
  }
}

/*

.mat-menu-panel

::ng-deep .mat-menu-content:not(:empty) {
  background-color: gray;
}
.icc-menu-icon-only {
  // vertical-align: center;
  padding: 0 !important;
  margin: 0;
  min-width: 32px;
  width: 32px;
}

.mat-menu-item {
  line-height: 30px;
  height: 30px;
}

.mat-option {
  line-height: 30px;
  height: 30px;
}
*/

@mixin menu-item-component-theme() {
  .icc-menu-panel {
    min-width: 150px;
  }

  .icc-menu-item {
    display: flex;
    height: 30px;
    padding-left: 5px;
    align-items: center;
  }

  .icc-menu-item-title {
    padding: 5px;
  }
}

/*
.icc-table-topbar {
  display: flex;
  align-items: center;
  width: 100%;
  height: 30px; // TODO variable

  .icc-menu-item {
    color: icc-theme(icc-text-color);
    background-color: icc-theme(icc-menu-background-color);
  }

  .mat-menu-item {
    line-height: 30px;
  }


} */

@mixin portal-component-theme() {
  .icc-portal-content {
    height: 100%;
    width: 100%;
    overflow: auto;
    // padding: 10px;
  }

  .icc-portal-text {
    background-color: icc-theme(icc-portal-background-color);
    color: icc-theme(icc-text-color);
    // box-shadow: 0 2px 14px 0 rgba(0, 0, 0, 0.2);
    // padding: 1rem;
    //font-size: 14px;
  }
}




@mixin field-view-button-component-theme() {
  .icc-button {
    border-width: 0px;
    width: 100%;
    height: 30px;
    text-align: left;
    color: icc-theme(icc-text-color) !important;
    background-color: icc-theme(icc-menu-background-color) !important;
  }
}


@mixin resize-directive-theme() {
  [IccResizeLeft], [IccResizeRight] {
    position: absolute;
    cursor: col-resize;
    top: 10px;
    bottom: 10px;
    width: 10px;
    right: 0;
  }

  [IccResizeLeft] {
    left: 0;
  }

  [IccResizeRight] {
    right: 0;
  }

  [IccResizeTop], [IccResizeBottom] {
    position: absolute;
    cursor: row-resize;
    height: 10px;
    left: 10px;
    right: 10px;
  }

  [IccResizeTop] {
    top: 0;
  }

  [IccResizeBottom] {
    bottom: 0;
  }

  [IccResizeTopLeft], [IccResizeBottomRight] {
    position: absolute;
    cursor: nwse-resize;
    width: 10px;
    height: 10px;
  }

  [IccResizeTopLeft] {
    top: 0;
    left: 0;
  }

  [IccResizeBottomRight] {
    bottom: 0;
    right: 0;
  }

  [IccResizeTopRight], [IccResizeBottomLeft] {
    position: absolute;
    cursor: nesw-resize;
    width: 10px;
    height: 10px;
  }

  [IccResizeTopRight] {
    top: 0;
    right: 0;
  }

  [IccResizeBottomLeft] {
    bottom: 0;
    left: 0;
  }

  [IccResizeLeftRight], [IccResizeRightLeft] {
    // position: absolute;
    cursor: col-resize;
    top: 10px;
    bottom: 10px;
    width: 2px;
    // right: 0;
  }

  [IccResizeTopBottom], [IccResizeBottomTop] {
    // position: absolute;
    cursor: row-resize;
    height: 2px;
    left: 10px;
    right: 10px;
  }
}



@mixin icc-theme-components() {
  @include table-header-component-theme();
  @include table-view-component-theme();
  @include tree-view-component-theme();
  @include menu-component-theme();
  @include menu-item-component-theme();
  @include field-view-button-component-theme();
  @include portal-component-theme();

  @include resize-directive-theme();
}

