@use "../../../public/shared.module.scss";
@use "../editor-tabs-bar-variables.module.scss";
@use "../../essential/dropdown-menu/dropdown-menu-variables.module.scss";

$tabMenuLeft: var(--tab-menu-left);

:root {
  --tab-menu-left: 0;
}

:export {
  tabMenuLeft: --tab-menu-left;
}

.tab {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: 1fr (
      editor-tabs-bar-variables.$tabMenuButtonWidth + editor-tabs-bar-variables.$tabMenuButtonGradientSpace
    ) * 1px;

  align-items: center;
  justify-items: start;
  background-color: shared.theme-var(--editor-tab-background);
  overflow: hidden;
  white-space: nowrap;
  padding: 0 0 0 8px;

  &.tab-selected {
    background-color: shared.theme-var(--editor-background);
  }

  &.tab-focused {
    outline: 2px solid;
    outline-offset: -2px;
  }

  &.rename-tab {
    grid-template-columns: 1fr;
    padding-right: 8px;
  }
}

.tab-button {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: fit-content(100%) 1fr;
  grid-row: 1;
  grid-column: span 3 / -1;
  column-gap: 3px;
  align-items: center;
  border: unset;
  background-color: transparent;
  color: shared.theme-var(--editor-syntax-highlight-neutral);
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: 0;

  &:focus-visible {
    outline: none;
  }
}

.tab-icon {
  display: grid;
  width: editor-tabs-bar-variables.$tabIconWidth * 1px;
  height: editor-tabs-bar-variables.$tabIconHeight * 1px;
  justify-content: center;
  align-items: center;
}

.tab-label {
  display: grid;
  text-align: start;
  width: 100%;
  height: editor-tabs-bar-variables.$tabLabelHeight * 1px;
  white-space: nowrap;
  align-items: center;
}

.rename-tab-form {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: 1fr fit-content(100%);
  column-gap: 5px;
}

.rename-tab-input {
  font-size: 0.875rem;
  letter-spacing: 0.01em;
  font-family: "Open Sans", "Lucida Grande", lucida, verdana, sans-serif;
  font-weight: 400;
  font-style: normal;
  padding: unset;
  outline-color: shared.theme-var(--button-secondary-outline-active);
  background: shared.theme-var(--input-field-background);
  color: shared.theme-var(--input-field-foreground);

  &.error {
    outline-color: #df7365;
  }
}

.tab-close-button-wrapper {
  display: grid;
  justify-content: end;
  align-items: center;
  height: 100%;

  // Allow text to go under the div
  // and take advantage of the gradient
  padding-left: 18px;
  margin-left: -18px;

  background: linear-gradient(90deg, rgba(0, 0, 0, 0), shared.theme-var(--editor-tab-background) 84%);

  &.tab-close-button-wrapper-visible {
    padding-right: 10px;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0), shared.theme-var(--editor-tab-background) 32%);
  }
}
.tab-close-button-wrapper-selected {
  padding-right: 10px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0), #22282A 32%);
}
:global(.light-theme) .tab-close-button-wrapper-selected {
  background: linear-gradient(90deg, rgba(0, 0, 0, 0), white 32%);
}

.tab-close-button {
  visibility: hidden;
  color: #374146;
  background: transparent;
  outline-offset: 4px;

  svg {
    path {
      fill: shared.theme-var(--editor-syntax-highlight-neutral);
    }
  }

  .tab-close-button-icon {
    width: 14px;
    height: 14px;
  }

  &.tab-close-button-visible {
    visibility: visible;
  }

  &.tab-close-button-open,
  &:hover {
    visibility: visible;
  }
}

$menuAndButtonWidth: -(dropdown-menu-variables.$dropdownMenuWidth) + editor-tabs-bar-variables.$tabMenuButtonWidth;
.tab-menu {
  top: 0 !important;
  margin-left: -20%;
}
.tab-menu-overlay {
  top: 0 !important;
  left: -50%;
}

kbd {
  color: shared.theme-var(--dropdown-item-label2);
}

.tab-skeleton-wrapper {
  display: grid;
  align-items: center;
  background-color: shared.theme-var(--editor-background);
  width: editor-tabs-bar-variables.$tabWidth * 1px;
}

.tab-skeleton {
  width: 50%;
  height: 60%;
  padding-left: 28px;
}

.tab-label-invalid {
  position: absolute;
  top: editor-tabs-bar-variables.$tabHeight * 1px;
  padding-left: 14px;
  background-color: shared.theme-var(--editor-background);
  opacity: 0.8;
  color: #7f8c8d;

  &.error {
    color: #da5b4a;
  }
}
