/*
  This stylesheet uses scss valiables for most of the colors / background-colors of the table
  to enable the customization of the displayed table without cloning the stylesheet into the
  own application.

  To modify table colors, add the following lines to the scss file of your application
  (this example modifies the color of the selected row - selectionType = single, multi or multiClick):

  $ngx-datatable-selected-active-background: yellow;
  $ngx-datatable-selected-active-background-hover: rgba(yellow, 0.2);

  @use '~@swimlane/ngx-datatable/themes/material.scss';
  @import '~@swimlane/ngx-datatable/assets/icons.css';

That's all.
*/

@use './ghost' as ghost;
@use './rows' as rows;

// common datatable colors
$ngx-datatable-background: #fff !default;
$ngx-datatable-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) !default;
$ngx-datatable-row-odd-background: #eee !default;

// default row and cell background colors
$ngx-datatable-default-background: #fff !default;
$ngx-datatable-default-background-hover: #eee !default;
$ngx-datatable-default-background-focus: #ddd !default;

// default background colors for cell selection style
$ngx-datatable-cellselection-background-hover: #eee !default;
$ngx-datatable-cellselection-background-focus: #ddd !default;

// background and text colors for selected cell / row
$ngx-datatable-selected-active-background: #304ffe !default;
$ngx-datatable-selected-active-color: #fff !default;
$ngx-datatable-selected-active-background-hover: #193ae4 !default;
$ngx-datatable-selected-active-color-hover: #fff !default;
$ngx-datatable-selected-active-background-focus: #2041ef !default;
$ngx-datatable-selected-active-color-focus: #fff !default;

// colors for header elements
$datatable-header-cell-background: #fff !default;
$datatable-header-cell-color: rgba(0, 0, 0, 0.54) !default;
$datatable-header-border-bottom-color: rgba(0, 0, 0, 0.12) !default;
$datatable-header-resize-handle-color: #eee !default;

// colors for table body elements
$datatable-disable-row-text-color: #83888e !default;
$datatable-row-detail-background: #f5f5f5 !default;
$datatable-body-cell-color: rgba(0, 0, 0, 0.87) !default;
$datatable-group-header-background: #f5f5f5 !default;
$datatable-group-header-border-top-color: #d9d8d9 !default;
$datatable-group-header-border-bottom-color: #d9d8d9 !default;
$datatable-body-row-border-bottom-color: #d9d8d9 !default;

// colors for footer elements
$datatable-footer-cell-color: rgba(0, 0, 0, 0.54) !default;
$datatable-footer-border-top-color: rgba(0, 0, 0, 0.12) !default;
$datatable-pager-color: rgba(0, 0, 0, 0.64) !default;
$datatable-pager-color-hover: rgba(0, 0, 0, 0.75) !default;
$datatable-pager-background-hover: rgba(158, 158, 158, 0.2) !default;
$datatable-pager-disabled-color: rgba(0, 0, 0, 0.26) !default;
$datatable-pager-disabled-background: transparent !default;
$datatable-pager-active-background: rgba(158, 158, 158, 0.2) !default;

// colors for summary row elements
$datatable-summary-row-background: #ddd !default;
$datatable-summary-row-background-hover: #ddd !default;

$datatable-ghost-cell-container-background: $ngx-datatable-background !default;
$datatable-ghost-cell-strip-background: #d9d8d9 !default;
$datatable-ghost-cell-strip-background-image: linear-gradient(
  to right,
  $datatable-ghost-cell-strip-background 0%,
  $datatable-ghost-cell-strip-background 10%,
  $ngx-datatable-background,
  transparent
) !default;
$datatable-ghost-cell-strip-radius: 0 !default;
$datatable-ghost-cell-animation-duration: 10s;

.ngx-datatable.material {
  @include ghost.ghost-cell-styles(
    $datatable-ghost-cell-container-background,
    $datatable-ghost-cell-strip-background,
    $datatable-ghost-cell-strip-background-image,
    $datatable-ghost-cell-strip-radius,
    $datatable-ghost-cell-animation-duration
  );

  @include rows.row-disabled-styles($datatable-disable-row-text-color);

  background: $ngx-datatable-background;
  box-shadow: $ngx-datatable-box-shadow;

  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  &.striped {
    .datatable-row-odd {
      background: $ngx-datatable-row-odd-background;
    }
  }

  &.single-selection,
  &.multi-selection,
  &.multi-click-selection {
    .datatable-body-row {
      &.active,
      &.active .datatable-row-group {
        background-color: $ngx-datatable-selected-active-background;
        color: $ngx-datatable-selected-active-color;
      }

      &.active:hover,
      &.active:hover .datatable-row-group {
        background-color: $ngx-datatable-selected-active-background-hover;
        color: $ngx-datatable-selected-active-color-hover;
      }

      &.active:focus,
      &.active:focus .datatable-row-group {
        background-color: $ngx-datatable-selected-active-background-focus;
        color: $ngx-datatable-selected-active-color-focus;
      }
    }
  }

  &:not(.cell-selection) {
    .datatable-body-row {
      &:hover,
      &:hover .datatable-row-group {
        background-color: $ngx-datatable-default-background-hover;
        transition-property: background;
        transition-duration: 0.3s;
        transition-timing-function: linear;
      }

      &:focus,
      &:focus .datatable-row-group {
        background-color: $ngx-datatable-default-background-focus;
      }
    }
  }

  &.cell-selection {
    .datatable-body-cell {
      &:hover:not(.row-disabled),
      &:hover:not(.row-disabled) .datatable-row-group {
        background-color: $ngx-datatable-cellselection-background-hover;
        transition-property: background;
        transition-duration: 0.3s;
        transition-timing-function: linear;
      }

      &:focus:not(.row-disabled),
      &:focus:not(.row-disabled) .datatable-row-group {
        background-color: $ngx-datatable-cellselection-background-focus;
      }

      &.active:not(.row-disabled),
      &.active:not(.row-disabled) .datatable-row-group {
        background-color: $ngx-datatable-selected-active-background;
        color: $ngx-datatable-selected-active-color;
      }

      &.active:hover:not(.row-disabled),
      &.active:hover:not(.row-disabled) .datatable-row-group {
        background-color: $ngx-datatable-selected-active-background-hover;
        color: $ngx-datatable-selected-active-color-hover;
      }

      &.active:focus:not(.row-disabled),
      &.active:focus:not(.row-disabled) .datatable-row-group {
        background-color: $ngx-datatable-selected-active-background-focus;
        color: $ngx-datatable-selected-active-color-focus;
      }
    }
  }

  /**
	 * Shared Styles
	 */
  .empty-row {
    block-size: 50px;
    text-align: start;
    padding-block: 0.5rem;
    padding-inline: 1.2rem;
    vertical-align: top;
    border-block-start: 0;
  }

  .loading-row {
    text-align: start;
    padding-block: 0.5rem;
    padding-inline: 1.2rem;
    vertical-align: top;
    border-block-start: 0;
  }

  /**
	 * Global Row Styles
	 */
  .datatable-header,
  .datatable-body {
    .horizontal-overflow {
      .datatable-row-left {
        background-color: $ngx-datatable-background;
        background-position: 100% 0;
        background-repeat: repeat-y;
        background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABCAYAAAD5PA/NAAAAFklEQVQIHWPSkNeSBmJhTQVtbiDNCgASagIIuJX8OgAAAABJRU5ErkJggg==');
      }

      .datatable-row-right {
        background-position: 0 0;
        background-color: $ngx-datatable-background;
        background-repeat: repeat-y;
        background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABCAYAAAD5PA/NAAAAFklEQVQI12PQkNdi1VTQ5gbSwkAsDQARLAIGtOSFUAAAAABJRU5ErkJggg==');
      }
    }
  }

  /**
	 * Header Styles
	 */
  .datatable-header {
    border-block-end: 1px solid $datatable-header-border-bottom-color;

    .datatable-row-left,
    .datatable-row-right {
      background-color: $datatable-header-cell-background;
    }

    .datatable-header-cell {
      flex-shrink: 0;
      text-align: start;
      padding-block: 0.9rem;
      padding-inline: 1.2rem;
      font-weight: 400;
      color: $datatable-header-cell-color;
      vertical-align: bottom;
      font-size: 12px;
      font-weight: 500;

      .datatable-header-cell-wrapper {
        position: relative;
      }

      &.longpress {
        .draggable::after {
          transition:
            transform 400ms ease,
            opacity 400ms ease;
          opacity: 0.5;
          transform: scale(1);
        }
      }

      .draggable::after {
        content: ' ';
        position: absolute;
        inset-block-start: 50%;
        inset-inline-start: 50%;
        margin-block: -30px 0;
        margin-inline: -30px 0;
        block-size: 60px;
        inline-size: 60px;
        background: #eee;
        border-radius: 100%;
        opacity: 1;
        filter: none;
        transform: scale(0);
        z-index: 9999;
        pointer-events: none;
      }

      &.dragging {
        .resize-handle {
          border-inline-end: none;
        }
      }
    }

    .resize-handle {
      border-inline-end: solid 1px $datatable-header-resize-handle-color;
    }
  }

  /**
	 * Body Styles
	 */
  .datatable-body {
    position: relative;

    .datatable-row-detail {
      background: $datatable-row-detail-background;
      padding: 10px;
    }

    .datatable-group-header {
      background: $datatable-group-header-background;
      border-block-end: solid 1px $datatable-group-header-border-bottom-color;
      border-block-start: solid 1px $datatable-group-header-border-top-color;

      .datatable-group-cell {
        padding-inline-start: 1.2rem;
        display: flex;
      }
    }

    datatable-row-def {
      background-color: $ngx-datatable-background;
    }

    .datatable-body-row {
      border-block-end: 1px solid $datatable-body-row-border-bottom-color;

      .datatable-body-cell {
        flex-shrink: 0;
        text-align: start;
        padding-block: 0.9rem;
        padding-inline: 1.2rem;
        vertical-align: top;
        border-block-start: 0;
        color: $datatable-body-cell-color;
        transition: inline-size 0.3s ease;
        font-size: 14px;
        font-weight: 400;

        // cell active class
        // &.active {
        //  background: #0829e0
        // }
      }
    }

    .progress-linear {
      display: block;
      position: sticky;
      inline-size: 100%;
      block-size: 0;
      z-index: 999;
      padding: 0;
      margin: 0;
      inset-block-start: 0;

      .container {
        display: block;
        position: relative;
        overflow: hidden;
        inline-size: 100%;
        block-size: 5px;
        transform: translate(0, 0) scale(1, 1);
        background-color: rgb(170, 209, 249);

        .bar {
          transition: all 0.2s linear;
          animation: query 0.8s infinite cubic-bezier(0.39, 0.575, 0.565, 1);

          transition: -webkit-transform 0.2s linear;
          transition: transform 0.2s linear;
          background-color: rgb(16, 108, 200);

          position: absolute;
          inset-inline-start: 0;
          inset-block: 0;
          inline-size: 100%;
          block-size: 5px;
        }
      }
    }

    .custom-loading-indicator-wrapper {
      position: sticky;
      inset-block-start: 0;
      block-size: 0;
      z-index: 999;

      .custom-loading-content {
        inline-size: 100%;
        background-color: $ngx-datatable-default-background;
      }
    }
  }

  /**
	 * Footer Styles
	 */
  .datatable-footer {
    border-block-start: 1px solid $datatable-footer-border-top-color;
    font-size: 12px;
    font-weight: 400;
    color: $datatable-footer-cell-color;

    .page-count {
      line-height: 50px;
      block-size: 50px;
      padding-block: 0;
      padding-inline: 1.2rem;
    }

    .datatable-pager {
      margin-block: 0;
      margin-inline: 10px;

      .page-button {
        block-size: 22px;
        min-inline-size: 24px;
        line-height: 22px;
        padding-block: 0;
        padding-inline: 6px;
        border-radius: 3px;
        margin-block: 6px;
        margin-inline: 3px;
        text-align: center;
        color: $datatable-pager-color;
        text-decoration: none;
        border: 0;
        background: none;

        &:hover {
          color: $datatable-pager-color-hover;
          background-color: $datatable-pager-background-hover;
        }

        &.active {
          background-color: $datatable-pager-active-background;
          font-weight: bold;
        }

        &:disabled {
          color: $datatable-pager-disabled-color;
          background-color: $datatable-pager-disabled-background;
        }
      }

      .datatable-icon-left,
      .datatable-icon-skip,
      .datatable-icon-right,
      .datatable-icon-prev {
        display: inline-block;
        vertical-align: middle;
        font-size: 20px;
        line-height: 20px;
        padding-block: 0;
      }
    }
  }

  // Summary row styles
  .datatable-summary-row {
    .datatable-body-row {
      background-color: $datatable-summary-row-background;

      &:hover {
        background-color: $datatable-summary-row-background-hover;
      }

      .datatable-body-cell {
        font-weight: bold;
      }
    }
  }
}

/**
 * Checkboxes
**/
.datatable-checkbox {
  position: relative;
  margin: 0;
  cursor: pointer;
  vertical-align: middle;
  display: inline-block;
  box-sizing: border-box;
  padding: 0;

  input[type='checkbox'] {
    position: relative;
    margin-block: 0;
    margin-inline: 0 1rem;
    cursor: pointer;
    outline: none;

    &::before {
      transition: all 0.3s ease-in-out;
      content: '';
      position: absolute;
      inset-inline-start: 0;
      z-index: 1;
      inline-size: 1rem;
      block-size: 1rem;
      border: 2px solid #f2f2f2;
    }

    &:checked::before {
      transform: rotate(-45deg);
      block-size: 0.5rem;
      border-color: #009688;
      border-block-start-style: none;
      border-inline-end-style: none;
    }

    &::after {
      content: '';
      position: absolute;
      inset-block-start: 0;
      inset-inline-start: 0;
      inline-size: 1rem;
      block-size: 1rem;
      background: #fff;
      cursor: pointer;
    }
  }
}

/**
 * Progress bar animations
 */
@keyframes query {
  0% {
    opacity: 1;
    transform: translateX(35%) scale(0.3, 1);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) scale(0, 1);
  }
}
