@use "../base/var";
@use "../base/color";
@use "../base/text";

// An individual (list) item with support for icon/img, content and actions.
:host(wy-item),
[part~="wy-item"] {
  --wy-component-color: #{color.token(--wy-on-surface)};
  display: flex;
  //clip-path: border-box;
  box-sizing: border-box;
  min-width: 0;
}

[part~="wy-item-rounded"] {
  border-radius: var.default(--wy-border-radius);
}

[part~="wy-item-rounded-outer"] {
  border-radius: var.default(--wy-border-radius-outer);
}

// Item nesting
[part~="wy-item-inner"] {
  display: flex;
  position: relative;
  align-items: center;
  text-decoration: none;
  gap: var.default(--wy-gap);
  padding: var.default(--wy-padding);
  flex: 1 1 100%;
  min-width: 0;
}

[part~="wy-item-inner-no-padding"] {
  padding: 0;
}


// fixed height item
[part~="wy-item-sm"] {
  min-height: var.wy-rem(2);
  padding: 0 var.default(--wy-padding);  
}

// fixed height item
[part~="wy-item-md"] {
  min-height: var.wy-rem(3);
}

// Fixed height item with room for larger icon and two rows of content
[part~="wy-item-lg"] {
  min-height: var.wy-rem(4.5);
}

// Alignment for inner items
[part~="wy-item-top"] {
  align-items: flex-start;
}

// Item content
[part~="wy-item-body"] {
  width: 100%;
  min-width: 0;
  min-height: 100%;
  display: flex;
}

// Multi row layout for content
[part~="wy-item-rows"] {
  display: flex;
  flex-direction: column;
  min-width: 0;
  justify-content: space-evenly;
  flex: 1 1 100%;
}

// A row when using multi rows
[part~="wy-item-row"] {
  display: flex;
  align-items: center;
  column-gap: var.default(--wy-gap);
  min-height: calc(var.default(--wy-button-line-height) * var.default(--wy-size));
}

[part~="wy-item-title"] {
  a {
    @include text.stretched-link;
    color: inherit;
    text-decoration: none;
  }

  color: var(--wy-component-color);
  font-size: var.default(--wy-item-title-font-size);
  font-weight: var.default(--wy-item-title-font-weight);
  @include text.truncate;
}

[part~="wy-item-image"] {
  display: contents;
}

// Normal content text
[part~="wy-item-text"] {
  color: var(--wy-component-color);

  @supports (color: color(from var(--wy-component-color) srgb r g b / var.default(--wy-opacity-muted))) {
    color: color(from var(--wy-component-color) srgb r g b / var.default(--wy-opacity-muted));
  }

  font-size: var.default(--wy-font-size-sm);

  @include text.truncate;
}

[part~="wy-item-text-sm"] {
  font-size: var.default(--wy-font-size-xs);
}

[part~="wy-item-meta"] {
  white-space: nowrap;
}

// For items with more than one action, and items with top/bottom positioned actions
[part~="wy-item-actions"] {
  --wy-component-background-color: transparent;
  display: flex;
  align-items: center;
  justify-items: flex-end;
  flex: 0 0 auto;
  gap: var.default(--wy-gap-sm);
}

// Alignment for actions
[part~="wy-item-actions-top"] {
  align-self: flex-start;
  margin: var.wy-rem(-0.25);
}

[part~="wy-item-actions-bottom"] {
  align-self: flex-start;
  margin: var.wy-rem(-0.125) 0 var.wy-rem(-0.625);
}

[part~="wy-item-left"] {
  margin-right: auto;
}

[part~="wy-item-right"] {
  margin-left: auto;
}

[part~="wy-read"] {
  opacity: var.default(--wy-opacity-muted);
  --wy-component-color: #{color.token(--wy-outline)};
}

[part~="wy-unread"] {
  --wy-component-color: color.token(--wy-on-surface);
  [part~="wy-item-title"],
  [part~="wy-item-text"] {
    font-weight: var.default(--wy-font-weight-bold);
    color: var(--wy-component-color);
  }
}

// An actionable item with hover, disabled, and active states.
[part~="wy-item-interactive"] {
  background-color: var(--wy-component-background-color);
  color: var(--wy-component-color);

  user-select: none;
  cursor: pointer;

  // Hover state
  &:hover,
  &:focus {
    --wy-component-background-color: var(--wy-component-background-color-hover, #{color.token(--wy-surface-layer-high)});
    text-decoration: none;
  }

  &:active {
    --wy-component-background-color: var(--wy-component-background-color-active, #{color.token(--wy-surface-layer-highest)});
  }

  &[part~="wy-disabled"],
  &:disabled {
    opacity: var.default(--wy-opacity-disabled);
    pointer-events: none;
  }

  &[part~="wy-selected"] {
    // selected?
    --wy-component-background-color: var(--wy-component-background-color-selected, #{color.token(--wy-secondary-container)});
    --wy-component-color: var(--wy-component-color-selected, #{color.token(--wy-on-secondary-container)});
    background-color: var(--wy-component-background-color);
    color: var(--wy-component-color);
    border-color: var(--wy-component-background-color);
  }
}

[part~="wy-item-trashed"] {
  text-decoration: line-through;
  opacity: var.default(--wy-opacity-disabled);

  &[part~="wy-item-interactive"]:hover {
    opacity: 1;
  }
}

// A list of items with rounded corners and spacing to visually group them together
[part~="wy-item-list"] {
  display: flex;
  flex-direction: column;
  gap: var.default(--wy-border);
  min-width: 0;
}

[part~="wy-item-list-filled"] {
  --wy-component-color: #{color.token(--wy-on-surface)};
  
  --wy-component-background-color: #{color.token(--wy-surface-layer-low)};
  --wy-component-background-color-hover: #{color.token(--wy-surface-layer-lowest)};
  --wy-component-background-color-active: #{color.token(--wy-surface-layer-lowest)};
}

// A list of items with rounded corners and spacing to visually group them together
[part~="wy-item-list-rounded"] {
  border-radius: var.default(--wy-border-radius-sm);
  clip-path: content-box;
}

// A list of items with rounded corners and spacing to visually group them together
[part~="wy-item-list-rounded-outer"] {
  border-radius: var.default(--wy-border-radius-outer);
  clip-path: content-box;
}

// A list of items with rounded corners and borders to visually group them together
[part~="wy-item-list-bordered"] {
  border: var.default(--wy-border) solid #{color.token(--wy-outline-variant)};
  gap: 0;

  > :not(slot),
  ::slotted(*) {
    border-left: none;
    border-right: none;
  }

  > :not(slot):not(:first-child),
  ::slotted(*:not(:first-child)) {
    border-top: var.default(--wy-border) solid #{color.token(--wy-outline-variant)};
  }
}
