// Kit-internal mixins for host inputs that embed `_internal/` affordances (clear button,
// emoji picker, password toggle, ...). NOT exported through `styles/` — relative-imported
// only from host components inside `src/lib/ui/`. The `--_--input-affordance--opacity` and
// `--_--input-affordance--scale` custom properties are INTENTIONALLY referenced only inside
// this file — host components and affordances consume them through these mixins, never by
// name.
//
// Layout contract: affordances are revealed by binding `opacity` to the host's reveal
// state, and they collapse their own width + leading margin to zero when hidden (so the
// input text can use the full available width). Hosts opt out of the size collapse by
// overriding `--_--input-affordance--scale: 1` after including `host` (e.g. Textarea,
// where collapsing affordance width in a bottom-aligned layout would shift the trailing
// edge while the textarea grows).

// Declare the host as an input-affordance container. Hides affordances by default and
// reveals them on the universal `:hover` / `:focus-within` triggers (lowered specificity
// via `:where()` so non-interactive host modifiers can override by source order). Hosts
// that need extra component-specific reveal triggers (e.g. DatePicker's `&--open` when
// the popover is portaled outside the host) wrap their selector around
// `@include affordance.reveal;`. Hosts that need to PIN affordances hidden in
// non-interactive states (`&--disabled`, `&--readonly`, `&--inert`) use `affordance.suppress`.
@mixin host {
  --_--input-affordance--opacity: 0;
  --_--input-affordance--scale: 0;

  &:where(:hover),
  &:where(:focus-within) {
    @include reveal;
  }
}

// Force affordances visible at the current scope. Used by hosts to add component-specific
// reveal triggers on top of the universal `:hover` / `:focus-within` defaults from `host`,
// and by `InputAffordances static` to disable collapse entirely.
@mixin reveal {
  --_--input-affordance--opacity: 1;
  --_--input-affordance--scale: 1;
}

// Pin affordances to their hidden state regardless of host hover/focus — used by hosts in
// non-interactive modifier blocks (`--disabled`, `--readonly`, `--inert`) to prevent the
// universal `:where(:hover)` reveal from kicking in. Defined AFTER `host` in source so
// cascade order wins at equal specificity.
@mixin suppress {
  --_--input-affordance--opacity: 0;
  --_--input-affordance--scale: 0;
}

// Mark an element as affordance-revealed: its opacity, inline-size, and leading margin
// are bound to the host's reveal state. The intrinsic (revealed) inline-size and the
// leading-gap value are supplied by the affordance via its own CSS vars — pass them as
// arguments so the mixin can multiply them by the shared scale. Defaults to `1` for both
// vars so the element stays visible if used outside a host context.
@mixin revealed($size, $gap) {
  opacity: var(--_--input-affordance--opacity, 1);
  inline-size: calc(#{$size} * var(--_--input-affordance--scale, 1));
  margin-inline-start: calc(#{$gap} * var(--_--input-affordance--scale, 1));
}
