import { css } from 'lit';
import componentStyles from '../../styles/component.styles.mjs';

const styles = css`
  ${componentStyles}

  :host {
    display: inline-flex;
    align-items: center;
    --color: var(--flow-ui-tab-color);
    --active-label-color: var(--flow-ui-tab-active-label-color);
    --active-icon-color: var(--flow-ui-tab-active-icon-color);
    --min-size: auto;
  }

  .tab {
    display: inline-flex;
    max-width: var(--flow-ui-tab-max-width);
    align-items: center;
    justify-content: center;
    font-family: var(--flow-ui-tab-label-font-family);
    font-size: var(--flow-ui-tab-label-font-size);
    font-weight: var(--flow-ui-tab-label-font-weight);
    border-radius: var(--flow-ui-border-radius-medium);
    color: var(--flow-ui-tab-color);
    padding: var(--flow-ui-tab-padding);
    white-space: nowrap;
    user-select: none;
    cursor: pointer;
    transition:
      var(--transition-speed) box-shadow,
      var(--transition-speed) color;
  }

  :host([placement='top']) .tab,
  :host([placement='bottom']) .tab {
    min-width: var(--min-size);
  }

  :host([placement='start']) .tab,
  :host([placement='end']) .tab {
    min-height: var(--min-size);
  }

  /* Highlight icon only on hover */
  .tab:hover:not(.tab--disabled) .tab__icon {
    color: var(--flow-ui-tab-active-label-color);
  }

  .tab:focus {
    outline: none;
  }

  .tab:focus-visible:not(.tab--disabled) .tab__icon {
    color: var(--flow-ui-tab-active-icon-color);
  }

  .tab:focus-visible {
    outline: var(--flow-ui-focus-ring);
    outline-offset: calc(-1 * var(--flow-ui-focus-ring-width) - var(--flow-ui-focus-ring-offset));
  }

  .tab.tab--active:not(.tab--disabled) {
    color: var(--flow-ui-active-label-color);
  }

  .tab.tab--active:not(.tab--disabled) .tab__icon {
    color: var(--flow-ui-tab-active-icon-color);
  }

  .tab.tab--active:not(.tab--disabled) .tab__label {
    color: var(--flow-ui-tab-active-label-color);
  }

  .tab.tab--closable {
    padding-inline-end: var(--flow-ui-spacing-small);
  }

  .tab.tab--disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .tab__close-button {
    font-size: var(--flow-ui-font-size-small);
    margin-inline-start: var(--flow-ui-spacing-small);
  }

  .tab__close-button::part(base) {
    padding: var(--flow-ui-spacing-3x-small);
  }

  .tab__label-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--flow-ui-spacing-2x-small);
  }

  .tab__icon {
    font-size: var(--flow-ui-tab-icon-size);
  }

  .tab__label {
    overflow: hidden;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
  }

  @media (forced-colors: active) {
    .tab.tab--active:not(.tab--disabled) {
      outline: solid 1px transparent;
      outline-offset: -3px;
    }
  }
`;

export { styles as default };
