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

const styles = css`
  ${componentStyles}

  :host {
    display: block;
    outline: 0;
    z-index: 0;
  }

  :host(:focus) {
    outline: none;
  }

  slot:not([name])::slotted(flow-ui-icon) {
    margin-inline-end: var(--flow-ui-spacing-x-small);
  }

  .tree-item {
    position: relative;
    display: flex;
    align-items: stretch;
    flex-direction: column;
    color: var(--flow-ui-color-neutral-900);
    cursor: pointer;
    user-select: none;
  }

  .tree-item__checkbox {
    pointer-events: none;
  }

  .tree-item__expand-button,
  .tree-item__checkbox,
  .tree-item__label {
    font-family: var(--flow-ui-font-sans);
    font-size: var(--flow-ui-font-size-medium);
    font-weight: var(--flow-ui-font-weight-normal);
    line-height: var(--flow-ui-line-height-dense);
    letter-spacing: var(--flow-ui-letter-spacing-normal);
  }

  .tree-item--small .tree-item__expand-button,
  .tree-item--small .tree-item__checkbox,
  .tree-item--small .tree-item__label {
    font-size: var(--flow-ui-font-size-small);
    line-height: var(--flow-ui-line-height-denser);
  }

  .tree-item--small .tree-item__expand-button {
    padding: var(--flow-ui-spacing-2x-small);
  }

  .tree-item--large .tree-item__expand-button,
  .tree-item--large .tree-item__checkbox,
  .tree-item--large .tree-item__label {
    font-size: var(--flow-ui-font-size-large);
    line-height: var(--flow-ui-line-height-normal);
  }

  .tree-item__checkbox::part(base) {
    display: flex;
    align-items: center;
    margin-right: var(--flow-ui-spacing-x-small);
  }

  .tree-item__indentation {
    display: block;
    width: 1em;
    flex-shrink: 0;
  }

  .tree-item__expand-button {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: content-box;
    color: var(--flow-ui-color-neutral-800);
    padding: var(--flow-ui-spacing-x-small);
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    cursor: pointer;
  }

  .tree-item__expand-button {
    transition: var(--flow-ui-transition-medium) rotate ease;
  }

  .tree-item--expanded .tree-item__expand-button {
    rotate: 90deg;
  }

  .tree-item--expanded.tree-item--rtl .tree-item__expand-button {
    rotate: -90deg;
  }

  .tree-item--expanded slot[name='expand-icon'],
  .tree-item:not(.tree-item--expanded) slot[name='collapse-icon'] {
    display: none;
  }

  .tree-item:not(.tree-item--has-expand-button) .tree-item__expand-icon-slot {
    display: none;
  }

  .tree-item.tree-item--hidden {
    display: none;
  }

  .tree-item__expand-button--visible {
    cursor: pointer;
  }

  .tree-item__item {
    display: flex;
    align-items: center;
    border-inline-start: solid 3px transparent;
  }

  .tree-item--disabled .tree-item__item {
    opacity: 0.5;
    outline: none;
    cursor: not-allowed;
  }

  :host(:focus-visible) .tree-item__item {
    outline: var(--flow-ui-focus-ring);
    outline-offset: var(--flow-ui-focus-ring-offset);
    z-index: 2;
  }

  :host(:not([aria-disabled='true'])) .tree-item--selected .tree-item__item {
    background-color: var(--selected-background-color);
    border-inline-start-color: var(--selected-marker-color);
  }

  :host(:not([aria-disabled='true'])) .tree-item__expand-button {
    color: var(--flow-ui-color-neutral-800);
  }

  .tree-item__label {
    display: flex;
    align-items: center;
    transition: var(--flow-ui-transition-fast) color;
  }

  .tree-item__children {
    display: block;
    font-size: calc(1em + var(--indent-size, var(--flow-ui-spacing-medium)));
  }

  /* Indentation lines */
  .tree-item__children {
    position: relative;
  }

  .tree-item__children::before {
    content: '';
    position: absolute;
    top: var(--indent-guide-offset);
    bottom: var(--indent-guide-offset);
    left: calc(1em - (var(--indent-guide-width) / 2) - 1px);
    border-inline-end: var(--indent-guide-width) var(--indent-guide-style) var(--indent-guide-color);
    z-index: 1;
  }

  .tree-item--rtl .tree-item__children::before {
    left: auto;
    right: 1em;
  }

  @media (forced-colors: active) {
    :host(:not([aria-disabled='true'])) .tree-item--selected .tree-item__item {
      outline: dashed 1px SelectedItem;
    }
  }
`;

export { styles as default };
