@use "../abstracts/mixins";

.jenkins-table {
  --table-padding: 0.55rem;

  position: relative;
  width: 100%;
  background: var(--table-background);
  border-radius: calc(
    var(--table-border-radius) + (var(--card-border-width) * 2)
  );
  border: calc(var(--card-border-width) * 2) solid var(--table-background);
  border-bottom-width: var(--card-border-width);
  border-spacing: 0 var(--card-border-width);
  background-clip: padding-box;
  margin-bottom: var(--section-padding);

  // The '::before' pseudo-element is causing overflow issues in Firefox, so disable it for that browser
  @supports (not (-moz-appearance: none)) {
    &::before {
      content: "";
      position: absolute;
      inset: -3px -3px -2px;
      border: var(--jenkins-border--subtle);
      border-radius: inherit;
      pointer-events: none;
    }
  }

  * {
    -webkit-border-horizontal-spacing: 0;
    -webkit-border-vertical-spacing: 0;
  }

  & > thead {
    & > tr {
      & > th {
        color: var(--table-header-foreground);
        text-align: left;
        padding-top: calc(var(--table-padding) * 0.9);
        padding-bottom: calc((var(--table-padding) * 0.9) + 2px);
        padding-left: 1.6rem;
        font-size: var(--font-size-sm);
        font-weight: var(--font-bold-weight);

        &[align="center"] {
          text-align: center;
        }

        &[align="right"] {
          text-align: right;
        }

        &:first-of-type {
          padding-left: calc(var(--table-padding) * 2);
        }

        &:last-of-type {
          padding-right: var(--table-padding);
        }

        a {
          color: var(--table-header-foreground);
          font-weight: 700;

          span.sortarrow {
            width: 24px;
          }
        }

        svg {
          vertical-align: middle;
          width: 0.8rem;
          height: 0.8rem;
        }
      }
    }
  }

  & > tbody {
    & > tr {
      color: var(--table-body-foreground);

      & > td {
        background: var(--table-body-background);
        vertical-align: middle;
        padding: var(--table-padding) 0 var(--table-padding) 1.6rem;
        height: 3rem;

        &:first-of-type {
          padding-left: calc(var(--table-padding) * 2);
        }

        &:last-of-type {
          padding-right: var(--table-padding);
        }
      }

      // Style the rows so that the first and last have a larger border radius
      & > td:first-of-type {
        border-top-left-radius: var(--table-row-border-radius);
        border-bottom-left-radius: var(--table-row-border-radius);
      }

      & > td:last-of-type {
        border-top-right-radius: var(--table-row-border-radius);
        border-bottom-right-radius: var(--table-row-border-radius);
      }

      // First row
      &:first-of-type {
        & > td:first-of-type {
          border-top-left-radius: var(--table-border-radius);
        }

        & > td:last-of-type {
          border-top-right-radius: var(--table-border-radius);
        }
      }

      // Last row
      &:last-of-type {
        & > td:first-of-type {
          border-bottom-left-radius: var(--table-border-radius);
        }

        & > td:last-of-type {
          border-bottom-right-radius: var(--table-border-radius);
        }
      }
    }
  }

  &__cell__button-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  &__cell--tight {
    padding-left: 0 !important;
    text-align: right !important;
    white-space: nowrap;
    width: 4rem;
  }

  &__cell--checkbox {
    padding: calc(var(--table-padding) * 2) !important;
    vertical-align: top !important;
    width: calc((var(--table-padding) * 2) + 22px);
  }

  &__cell--no-wrap {
    white-space: nowrap;
  }

  &__button {
    display: inline-flex;
  }

  &__link,
  .sortheader {
    display: inline-flex;
  }

  &__link {
    .jenkins-menu-dropdown-chevron {
      top: 0;
    }
  }

  .jenkins-button {
    margin: -10px 0;
    padding: 0.5rem 0.75rem;
    min-height: 1.75rem;

    // Increase the size of symbols compared to regular buttons
    svg {
      width: 1.5rem !important;
      height: 1.5rem !important;
    }
  }

  &__button,
  &__icon {
    svg,
    .build-status-icon__wrapper,
    img {
      width: 1.5rem !important;
      height: 1.5rem !important;
    }
  }

  &--medium {
    --table-padding: 0.4rem !important;

    tbody > tr > td {
      height: 40px;
    }

    .jenkins-table__button,
    .jenkins-table__link,
    .jenkins-table__icon {
      svg,
      .build-status-icon__wrapper,
      img {
        width: 1.3rem !important;
        height: 1.3rem !important;
      }
    }

    .jenkins-button {
      padding: 0.4rem 0.6rem;

      svg {
        width: 1.3rem !important;
        height: 1.3rem !important;
      }
    }
  }

  &--auto-width {
    width: auto !important;
  }

  &--small {
    --table-padding: 0.2rem;

    tbody > tr > td {
      height: 34px;
    }

    .jenkins-table__button,
    .jenkins-table__link,
    .jenkins-table__icon {
      svg,
      .build-status-icon__wrapper,
      img {
        width: 1rem !important;
        height: 1rem !important;
      }
    }

    .jenkins-button {
      padding: 0.3rem 0.5rem;

      svg {
        width: 1rem !important;
        height: 1rem !important;
      }
    }
  }

  &__button,
  &__link {
    color: var(--link-color);
  }

  &__button,
  .sortheader,
  &__link {
    @include mixins.item($border: false);

    align-items: center;
    justify-content: center;
    appearance: none;
    outline: none;
    border: none;
    margin: 0;
    padding: 0;
    cursor: pointer;
    color: inherit;
    font-weight: inherit;
    font-size: inherit;
    background: transparent;
    text-decoration: none !important;
    line-height: 1 !important;
    transition: var(--standard-transition);

    &::before,
    &::after {
      inset: -7px -10px;
      border-radius: 6px;
    }
  }

  &__badge {
    @include mixins.item;

    --item-background: color-mix(in sRGB, currentColor 5%, transparent);
    --item-background--hover: color-mix(in sRGB, currentColor 10%, transparent);
    --item-background--active: color-mix(
      in sRGB,
      currentColor 15%,
      transparent
    );
    --item-box-shadow--focus: color-mix(in sRGB, currentColor 5%, transparent);

    margin-left: 1rem !important;
    border-radius: 13px;

    &::before,
    &::after {
      inset: -5px -8px;
    }
  }
}
