/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@import url("chrome://global/content/elements/moz-visual-picker-item.tokens.css");

:host {
  cursor: default;
  display: flex;
}

:host([labelposition="outside"]) {
  flex-direction: column;
  align-items: center;

  .text-content {
    text-align: center;
    padding-top: var(--space-small);
  }
}

:host([orientation="vertical"]) {
  width: 100%;

  .image-item {
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: var(--space-medium);

    img {
      width: var(--visual-picker-item-image-size, var(--size-image-xlarge));
      height: var(--visual-picker-item-image-size, var(--size-image-xlarge));
      padding: var(--visual-picker-item-padding, 0);
      object-fit: cover;
      flex-shrink: 0;
    }
  }
}

/**
 * Unnested because :not() must live inside :host()
 */
/* stylelint-disable-next-line stylelint-plugin-mozilla/no-has-selector */
:host([orientation="vertical"]:not([labelposition="outside"])) .text-content:has(.label, .description) {
  text-align: start;
  flex: 1;
}

.picker-item {
  --visual-picker-item-border-radius-inner: calc(var(--visual-picker-item-border-radius) - var(--visual-picker-item-border-width));

  appearance: none;
  overflow: hidden;
  border: var(--visual-picker-item-border-width) solid var(--visual-picker-item-border-color);
  border-radius: var(--visual-picker-item-border-radius);
  /* The margin needs to account for the increased border-width on the checked item. */
  /* stylelint-disable-next-line stylelint-plugin-mozilla/use-design-tokens */
  margin: calc(var(--visual-picker-item-border-width-checked) - var(--visual-picker-item-border-width));
  background-color: var(--button-background-color-ghost);
  padding: 0;
  flex: 1;

  &:focus {
    outline: none;
  }

  &:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
  }

  &:hover {
    background-color: var(--button-background-color-ghost-hover);
  }

  &:hover:active:not(:disabled) {
    background-color: var(--button-background-color-ghost-active);
  }

  &[checked] {
    --visual-picker-item-border-width: var(--visual-picker-item-border-width-checked);
    border-color: var(--border-color-selected);
    margin: 0;
  }

  ::slotted(:first-child) {
    --visual-picker-item-child-border-radius: var(--visual-picker-item-border-radius-inner);
    border-radius: var(--visual-picker-item-child-border-radius);
  }

  /* stylelint-disable-next-line stylelint-plugin-mozilla/no-has-selector */
  .text-content:has(.label, .description) {
    padding: var(--space-small) var(--space-medium);
    text-align: center;
  }

  img {
    display: block;
    width: 100%;
  }
}

.label {
  margin: 0;
}

.description {
  margin: 0;
  font-size: var(--font-size-small);
  color: var(--text-color-deemphasized);
}

.label + .description {
  margin-block-start: var(--space-xsmall);
}

.image-item {
  background-color: var(--background-color-box);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  &:hover {
    background-color: var(--button-background-color-hover);
  }

  &:hover:active {
    background-color: var(--button-background-color-active);
  }
}
