@import './theme.css';
@import './utilities.css';

.react-aria-Table {
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--overlay-background);
  overflow: clip;
  outline: none;
  border-spacing: 0;
  align-self: start;
  width: 100%;
  word-break: break-word;
  forced-color-adjust: none;
  font: var(--font-size) system-ui;

  div& {
    padding: 0;
  }

  &[data-focus-visible] {
    outline: 2px solid var(--focus-ring-color);
  }

  &[data-drop-target] {
    outline: 2px solid var(--highlight-background);
    background: var(--highlight-overlay);
  }

  &:has(.react-aria-TableBody[data-empty]) {
    height: 100%;
    min-height: 100px;
  }

  .react-aria-TableHeader {
    color: var(--text-color);
  }

  .react-aria-TableBody {
    padding: var(--spacing-1);

    &[data-empty] {
      text-align: center;
      font-style: italic;
    }
  }
}

.react-aria-Row {
  outline: none;
  cursor: default;
  color: var(--text-color);
  position: relative;
  transform: scale(1);
  transition-property: background, color;
  transition-duration: 200ms;
  -webkit-tap-highlight-color: transparent;

  tr:last-child& {
    border-radius: 0 0 var(--radius) var(--radius);
  }

  &[data-focus-visible] {
    outline: 2px solid var(--focus-ring-color);
    outline-offset: -2px;
  }

  &[data-pressed] {
    background: var(--gray-100);
  }

  &:nth-child(2n) {
    background: var(--gray-100);
    &[data-pressed] {
      background: var(--gray-200);
    }
  }

  &[data-selected] {
    background: var(--highlight-background);
    color: var(--highlight-foreground);
    --focus-ring-color: var(--highlight-foreground);

    &[data-focus-visible],
    .react-aria-Cell[data-focus-visible] {
      outline-offset: -4px;
    }

    &[data-pressed] {
      background: var(--highlight-background-pressed);
    }
  }

  &[data-disabled] {
    color: var(--text-color-disabled);
  }

  &[data-href] {
    cursor: pointer;
  }

  &[data-dragging] {
    opacity: 0.6;
    transform: translateZ(0);
  }

  &[data-drop-target] {
    outline: 2px solid var(--highlight-background);
    background: var(--highlight-overlay);
    z-index: 4;
  }

  .drag-button {
    all: unset;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    text-align: center;

    svg {
      width: var(--spacing-4);
      height: var(--spacing-4);
    }

    &[data-focus-visible] {
      border-radius: 4px;
      outline: 2px solid var(--focus-ring-color);
    }
  }

  .react-aria-DropIndicator[data-drop-target] {
    outline: 1px solid var(--highlight-background);
    transform: translateZ(0);
  }
}

.react-aria-Cell,
.react-aria-Column {
  padding: var(--spacing-2);
  text-align: left;
  outline: none;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;

  div& {
    display: flex;
    align-items: center;
    height: 100%;
  }

  &:is(.react-aria-Row:last-child > :first-child) {
    border-end-start-radius: var(--radius);
  }

  &:is(.react-aria-Row:last-child > :last-child) {
    border-end-end-radius: var(--radius);
  }

  &[data-focus-visible] {
    outline: 2px solid var(--focus-ring-color);
    outline-offset: -2px;
  }
}

.react-aria-Column {
  --button-color: var(--gray);
  --button-border: transparent;
  --button-shadow: transparent;
  --button-border-size: 0px;
  cursor: default;
  border-bottom: 0.5px solid var(--border-color);
  border-inline-end: 0.5px solid var(--border-color);
  position: relative;
  z-index: calc(sibling-count() - sibling-index());

  &:last-child {
    border-inline-end: none;
  }

  &[data-pressed] {
    background: var(--gray-200);
  }

  &[data-sort-direction] {
    --button-color: var(--tint);

    &[data-pressed] {
      background: var(--tint-200);
    }
  }

  .column-header {
    display: flex;
    align-items: center;
    font-weight: 600;
  }

  .column-name {
    flex: 1;
    font: inherit;
    text-align: start;
    color: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-color: transparent;
    border-radius: var(--radius-sm);

    &[data-focus-visible] {
      outline: 2px solid var(--focus-ring-color);
      outline-offset: 2px;
    }
  }

  .sort-indicator {
    padding: 0 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  &:not([data-sort-direction]) .sort-indicator {
    visibility: hidden;
  }
}

.react-aria-ColumnResizer {
  width: 1px;
  border-radius: var(--radius-sm);
  background-color: var(--gray-500);
  padding: 0 var(--spacing-2);
  translate: var(--spacing-4) 0;
  height: 32px;
  margin: -16px 0;
  flex: 0 0 auto;
  touch-action: none;
  box-sizing: content-box;
  background-clip: content-box;

  &[data-resizable-direction='both'] {
    cursor: ew-resize;
  }

  &[data-resizable-direction='left'] {
    cursor: e-resize;
  }

  &[data-resizable-direction='right'] {
    cursor: w-resize;
  }

  &[data-focus-visible] {
    background-color: var(--focus-ring-color);
    outline: 2px solid var(--focus-ring-color);
    outline-offset: -2px;
  }

  &[data-resizing] {
    width: 2px;
    background-color: var(--highlight-background);
  }
}

.react-aria-Cell {
  transform: translateZ(0);
  --border-color: var(--gray-300);
  tr:not(:last-child) & {
    border-bottom: 0.5px solid var(--border-color);
  }

  [data-selected]:has(+ [data-selected]) & {
    --border-color: rgb(255 255 255 / 0.3);
  }

  @media (forced-colors: active) {
    --border-color: ButtonBorder;
  }

  &[data-tree-column] {
    --chevron-placeholder: var(--spacing-5);
    padding-inline-start: calc(
      var(--spacing-2) + (var(--table-row-level) - 1) * var(--spacing-4) +
        var(--chevron-placeholder)
    );

    &[data-has-child-items] {
      --chevron-placeholder: 0px;
    }
  }

  .react-aria-Button[slot='chevron'] {
    all: unset;
    vertical-align: middle;
    margin-inline-end: var(--spacing-1);

    svg {
      rotate: 0deg;
      transition: rotate 200ms;
      fill: none;
      stroke: currentColor;
      stroke-width: 3px;
      width: var(--spacing-4);
      height: var(--spacing-4);
    }
  }

  &[data-expanded] .react-aria-Button[slot='chevron'] svg {
    rotate: 90deg;
  }
}

.react-aria-DropIndicator[data-drop-target] {
  outline: 1px solid var(--highlight-background);
  transform: translateZ(0);
  translate: calc(68px + (var(--table-row-level) - 1) * var(--spacing-4)) 0;
}

.react-aria-Row .react-aria-CheckboxButton {
  --checkmark-color: var(--highlight-background);
  &[data-selected] .indicator {
    --indicator-color: var(--highlight-foreground);
    --indicator-shadow: transparent;
  }
}

.react-aria-ResizableTableContainer {
  width: 100%;
  overflow: auto;
  position: relative;
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--overlay-background);

  .react-aria-Table {
    border: none;
    border-radius: 0;

    &:has(.react-aria-TableBody[data-empty]) {
      height: 100%;
    }
  }

  .react-aria-TableHeader {
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .react-aria-Cell {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.react-aria-Cell img {
  height: 30px;
  width: 30px;
  object-fit: cover;
  display: block;
}

.react-aria-TableLoadingIndicator {
  height: 32px;
  position: relative;
}

.react-aria-TableFooter {
  font-weight: bold;
  background: var(--gray-200);
}
