@import '../../variables';
@import '../../mixins';

@include exports('components.datagrid') {
  $col-padding-left: 15px;
  $col-padding-right: 15px;
  $animation-duration: 0.2s;
  $animation-type: ease;

  .fui-datagrid-dragdrop-icon {
    visibility: hidden;
    opacity: 0;
    position: absolute;

    display: inline-block;
    fill: $gray-500;

    user-select: none !important;

    &.fui-datagrid-dragdrop-move {
      width: 18px;
      height: 18px;
    }

    &.fui-datagrid-dragdrop-delete {
      width: 20px;
      height: 20px;
    }
  }

  .fui-datagrid-body-row-action-menu {
    position: absolute;
    right: 0;
    top: 1px;
    width: auto;
    display: none;
    flex-flow: column nowrap;
    justify-content: center;
    align-items: center;
    align-content: center;
    z-index: $zindex-dropdown - 1;
    background-color: $gray-100;

    &.fui-row-selected {
      background-color: $blue-selected-hover;

      &:hover {
        background-color: $blue-selected-hover;
      }
    }

    &.fui-datagrid-action-menu-visible {
      display: flex;
    }

    &:hover {
      background-color: $gray-100;
      display: flex;

      .action-menu-icon {
        color: $gray-900;
      }
    }
  }

  .fui-datagrid-body-empty {
    display: flex;
    flex-flow: column nowrap;
    justify-content: center;
    align-items: center;
    align-content: center;
    height: 100px;

    .fui-body-empty-icon {
      flex: 1 0 auto;
      display: flex;
      flex-flow: column nowrap;
      justify-content: flex-end;
      align-items: center;
      align-content: center;

      .fui-body-empty-icon-ico {
        width: 32px;
        height: 32px;
        color: $gray-500;
      }
    }

    .fui-body-empty-message {
      flex: 1 0 auto;
      display: flex;
      flex-flow: column nowrap;
      justify-content: flex-start;
      align-items: center;
      align-content: center;

      span {
        font-size: $font-size-sm;
        font-weight: $font-weight-normal;
        color: $gray-500;
      }
    }
  }

  .fui-datagrid-dragger {
    position: fixed;
    display: block;
    border-radius: $border-radius;
    background-color: $gray-100;
    border: 1px solid $gray-300;
    padding: 0 10px;
    z-index: $zindex-fixed;
    cursor: move;
    font-size: $font-size-sm;
    font-weight: $font-weight-bold;

    user-select: none;

    .fui-datagrid-dragger-icon {
      display: inline-block;

      .fui-datagrid-dragdrop-icon {
        visibility: visible;
        opacity: 1;
        position: relative;
      }
    }

    .fui-datagrid-dragger-label {
      display: inline-block;
      margin-left: 10px;
    }
  }

  .fui-datagrid {
    display: block;
    position: relative;

    font-size: $font-size-sm;
    font-weight: $font-weight-normal;
    color: $gray-900;
    font-family: $font-family-sans-serif;
    box-sizing: border-box;

    * {
      box-sizing: border-box;
    }

    &.fui-datagrid-has-vertical-scroll {
      .fui-datagrid-root-wrapper {
        .fui-datagrid-root-body-wrapper {
          .fui-datagrid-root-body {
            .fui-datagrid-body {
              .fui-datagrid-body-cliper {
                .fui-datagrid-body-viewport {
                  .scrollable-content {
                    .fui-datagrid-body-row {
                      &:last-of-type {
                        border-bottom: none !important;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    &.fui-datagrid-rounded-corners {
      .fui-datagrid-root-wrapper {
        border-radius: $border-radius;
      }

      &:not(.fui-datagrid-without-header).fui-datagrid-has-filter {
        .fui-datagrid-root-wrapper {
          border-top-left-radius: 0 !important;
          border-top-right-radius: 0 !important;
        }
      }

      &:not(.fui-datagrid-without-navigator).fui-datagrid-has-pager {
        .fui-datagrid-root-wrapper {
          border-bottom-left-radius: 0 !important;
          border-bottom-right-radius: 0 !important;
        }
      }
    }

    .fui-datagrid-root-wrapper {
      position: relative;
      display: flex;
      direction: ltr;
      -webkit-box-orient: vertical;
      -webkit-box-direction: normal;
      flex-direction: column;
      overflow: hidden;

      height: 100%;
      border: 1px solid $gray-300;

      .fui-datagrid-root-body-wrapper {
        -webkit-box-flex: 1;
        flex: 1 1 auto;
        height: 0;
        min-height: 0;

        display: flex;
        -webkit-box-orient: horizontal;
        -webkit-box-direction: normal;
        flex-direction: row;

        .fui-datagrid-root-body {
          height: 100%;

          overflow: hidden;
          -webkit-box-flex: 1;
          flex: 1 1 auto;
          width: 0;

          cursor: default;
          position: relative;
          display: flex;
          -webkit-box-orient: vertical;
          -webkit-box-direction: normal;
          flex-direction: column;

          background: $white;
          user-select: none !important;

          .fui-datagrid-horizontal-scroll {
            position: relative;

            display: flex;
            width: 100%;
            min-width: 0;
            -webkit-box-orient: horizontal;
            flex-direction: row;

            .fui-horizontal-right-spacer {
              overflow: hidden;
              height: 100%;
              flex-grow: 1000;
            }

            .fui-datagrid-body-horizontal-scroll-viewport {
              overflow-x: scroll;
              overflow-y: hidden;

              position: relative;
              height: 100%;
              min-width: 0;
              -webkit-box-flex: 1;
              flex: 1 1 auto;

              .fui-datagrid-body-horizontal-scroll-container {
                position: relative;
              }
            }
          }

          .fui-datagrid-header {
            -webkit-box-orient: horizontal;
            -webkit-box-direction: normal;
            flex-direction: row;

            display: flex;
            width: 100%;
            white-space: nowrap;

            overflow: hidden;

            border-bottom: 1px solid $gray-300;

            .fui-datagrid-header-viewport {
              display: block;
              position: relative;
              height: 100%;
              min-width: 0;

              overflow: hidden;

              -webkit-box-flex: 1;
              flex: 1 1 auto;

              .fui-datagrid-header-container {
                position: relative;
                display: block;

                height: 100%;
                white-space: nowrap;

                background-color: $gray-100;

                .fui-datagrid-header-row {
                  display: block;
                  border: none;
                  position: absolute;
                  overflow: hidden;

                  .fui-datagrid-header-cell {
                    padding-left: $col-padding-left;
                    padding-right: $col-padding-right;

                    font-weight: $font-weight-bold;

                    display: inline-block;
                    height: 100%;
                    position: absolute;
                    vertical-align: bottom;

                    visibility: hidden;
                    opacity: 0;

                    overflow: hidden;

                    .fui-datagrid-selection-box {
                      margin-top: 0.875rem !important;
                    }

                    &.fui-datagrid-column-visible {
                      visibility: visible;
                      opacity: 1;
                    }

                    &.moving {
                      &.dragging {
                        background-color: $white;
                        cursor: move !important;
                      }

                      &.with-animation {
                        transition: left $animation-duration;
                      }
                    }

                    &.sortable {
                      cursor: pointer;
                    }

                    &::after {
                      border-right: 1px solid $gray-300;
                      content: ' ';
                      height: 100%;
                      position: absolute;
                      text-indent: -2000px;
                      top: 0;
                      right: 0;
                    }

                    .fui-datagrid-dragdrop-move,
                    .fui-datagrid-dragdrop-delete {
                      position: absolute;
                      visibility: hidden;
                      opacity: 0;
                    }

                    .fui-datagrid-header-label {
                      height: 100%;
                      display: flex;

                      overflow: hidden;
                      text-overflow: ellipsis;

                      user-select: none;

                      .fui-datagrid-header-text {
                        display: inline-block;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        white-space: nowrap;
                        float: left;
                      }

                      .fui-datagrid-sort {
                        display: inline-block;
                        float: left;
                        height: 100%;
                        margin: 0 0 0 5px;

                        .fui-datagrid-sort-asc,
                        .fui-datagrid-sort-desc {
                          width: 14px;
                          height: 14px;
                          color: $gray-500;

                          &:hover {
                            color: $gray-900;
                          }
                        }
                      }

                      .fui-datagrid-sort-badge {
                        display: inline-block;
                        margin: 0 0 0 5px;
                        height: 100%;
                        width: auto;
                        float: left;

                        .badge {
                          display: inline-block;
                          vertical-align: middle;
                          width: auto;
                          height: auto;
                          padding: 3px 4px;
                          color: $white;
                          font-size: $font-size-sm;
                          font-weight: $font-weight-bold;
                        }
                      }
                    }

                    &.lock-position {
                      .fui-datagrid-header-cell-resize {
                        cursor: default;
                      }
                    }

                    .fui-datagrid-header-cell-resize {
                      position: absolute;
                      z-index: 4;

                      width: 8px;
                      top: 0;
                      right: -4px;
                      cursor: col-resize;
                      height: 100%;
                    }

                    &.checkbox-column {
                      padding-right: 0;

                      .fui-datagrid-select-all-options-wrapper {
                        display: inline-block;

                        .fui-checkbox-wrapper {
                          display: inline-block;
                          float: left;
                          width: 20px;
                          max-width: 20px;
                        }

                        .fui-datagrid-select-all-select {
                          display: inline-block;

                          .btn {
                            padding: 0 0 0 5px !important;

                            .fui-caret {
                              width: 9px;
                              height: 9px;
                              fill: $gray-500;
                              vertical-align: baseline !important;
                            }

                            &:hover {
                              .fui-caret {
                                fill: $gray-900;
                              }
                            }
                          }
                        }
                      }

                      &::after {
                        display: none;
                      }

                      .fui-datagrid-header-cell-resize {
                        display: none;
                      }
                    }
                  }
                }
              }
            }
          }

          .fui-datagrid-body {
            -webkit-box-orient: horizontal;
            -webkit-box-direction: normal;
            flex-direction: row;

            overflow: hidden;

            display: flex;

            position: relative;
            min-width: 0;
            -webkit-box-flex: 1;
            flex: 1 1 auto;

            .fui-datagrid-body-cliper {
              min-height: 100%;

              -webkit-box-flex: 1;
              -ms-flex: 1;
              flex: 1;
              min-width: 0;
              overflow: hidden;

              display: block;

              &.with-fixed-height {
                &.with-empty-data {
                  display: flex;
                  justify-content: center;
                  flex-direction: column;
                }
              }

              .fui-grid-loading-wrapper {
                display: block;
                position: relative;
                min-height: 100px;
                height: 100%;
                width: 100%;

                .fui-grid-loading-screen {
                  position: absolute;
                  display: flex;
                  top: 0;
                  left: 0;
                  bottom: 0;
                  right: 0;

                  align-content: center;
                  align-items: center;
                  justify-content: center;

                  color: $gray-500;

                  .fui-datagrid-loading-icon {
                    @include fui-spinning-animation();
                  }
                }
              }

              .fui-datagrid-body-viewport {
                display: block;

                width: 100%;
                height: 100%;

                position: relative;
                min-width: 0;

                .fui-virtual-scroller-clipper {
                  position: relative;
                }

                .fui-datagrid-full-width-container {
                  width: 100%;

                  position: absolute;
                  top: 0;
                  left: 0;
                  pointer-events: none;
                }

                .fui-datagrid-body-container,
                .scrollable-content {
                  display: block;

                  .fui-datagrid-body-row {
                    position: relative;

                    white-space: nowrap;
                    width: 100%;

                    display: block;

                    &.selectable:hover,
                    &.selectable.hovered {
                      background-color: $gray-100;
                    }

                    &.selectable.selected {
                      background-color: $blue-selected;

                      &:hover,
                      &.hovered {
                        background-color: $blue-selected-hover;
                      }
                    }

                    border-style: solid;
                    border-width: 0 0 1px;
                    border-color: $gray-300;

                    .fui-datagrid-row-error {
                      display: block;
                      padding-left: $col-padding-left;
                      padding-right: $col-padding-right;

                      .fui-datagrid-row-error-icon {
                        display: inline-block;
                        width: 16px;
                        height: 16px;
                        color: $red;
                      }

                      .fui-error-message {
                        display: inline-block;
                        padding-left: map_get($spacers, 2); // 10px
                      }
                    }

                    .fui-datagrid-body-cell {
                      border: 1px solid transparent;
                      border-right: none;
                      border-left: none;

                      padding-left: $col-padding-left;
                      padding-right: $col-padding-right;

                      display: inline-block;
                      overflow: hidden;
                      position: absolute;
                      text-overflow: ellipsis;
                      white-space: nowrap;

                      height: 100%;

                      visibility: hidden;
                      opacity: 0;

                      &.moving {
                        &.with-animation {
                          transition: left $animation-duration;
                        }
                      }

                      &.fui-datagrid-column-visible {
                        visibility: visible;
                        opacity: 1;
                      }

                      .fui-datagrid-selection-box {
                        margin-top: 0.8125rem !important;
                      }
                    }
                  }
                }
              }
            }
          }

          .fui-datagrid-footer {
            display: block;
            position: relative;
            width: 100%;
            height: 100%;
            min-width: 0;
            overflow: hidden;

            .fui-datagrid-footer-row {
              display: block;
              position: relative;

              width: 100%;

              border-style: solid;
              border-width: 1px 0 0;
              border-color: $gray-300;

              overflow-y: hidden;
              overflow-x: auto;

              .fui-datagrid-footer-row-clipper {
                position: relative;
                display: block;
                height: 100%;
                overflow: hidden;

                .fui-datagrid-footer-cell {
                  border: 1px solid transparent;
                  border-right: none;
                  border-left: none;

                  padding-left: $col-padding-left;
                  padding-right: $col-padding-right;
                  position: absolute;

                  &,
                  .fui-datagrid-footer-cell-wrapper {
                    display: inline-block;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    height: 100%;
                    width: 100%;
                    font-weight: $font-weight-bold;
                  }

                  visibility: hidden;
                  opacity: 0;

                  &.moving {
                    &.with-animation {
                      transition: left $animation-duration;
                    }
                  }

                  &.fui-datagrid-column-visible {
                    visibility: visible;
                    opacity: 1;
                  }

                  .fui-datagrid-selection-box {
                    margin-top: 0.8125rem !important;
                  }
                }
              }
            }
          }
        }
      }

      .fui-datagrid-pager-wrapper {
      }
    }
  }

  // If within a modal, we need to change the z-index of the dropdowns.
  .fui-modal-anchor.fui-modal-open {
    .fui-datagrid-dropdown {
      z-index: $zindex-modal !important;
    }
  }
}
