/* 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/. */

:host {
  --line-container-height: var(--size-item-xlarge);
  --outer-border-radius: var(--border-radius-medium);
  --inner-border-radius: calc(var(--outer-border-radius) - 2px);
  --alert-color: var(--icon-color-warning);
  --input-field-color: var(--link-color);
  --input-field-color-hover: var(--button-text-color-ghost-hover);
  --input-field-color-active: var(--button-text-color-ghost-active);
  --copy-transition: opacity 250ms linear;
  --check-icon-color: var(--color-accent-attention);

  color: inherit;
  padding: 3px;
}

:host([linetype="password"]) {
  --alert-color: var(--icon-color-critical);
}

:host([linetype="username"]) {
  --alert-color: var(--icon-color-information);
}

:host([linetype="password"]),
:host([linetype="username"]) {
  /* We must give this component a fixed height because it will be used inside a virtual list which requires
  *  to know the height of its content. */
  --line-container-height: var(--size-item-xlarge);
  --input-field-color: var(--button-text-color);
}

:host([linetype="origin"]) {
  --line-container-height: 44px;
  border-radius: var(--outer-border-radius) var(--outer-border-radius) 0 0;

  .input-field {
    text-decoration: underline;
  }
}

:host(login-line:hover),
:host(login-line:focus-visible) {
  > .line-container {
    background-color: var(--button-background-color-ghost-hover);
  }

  .input-field,
  .line-container {
    color: var(--input-field-color-hover);
  }
}

:host(login-line:active) {
  > .line-container {
    background-color: var(--button-background-color-ghost-active);
  }

  .input-field,
  .line-container {
    color: var(--input-field-color-active);
  }
}

:host(concealed-login-line) {
  display: flex;
  padding: 0;

  > login-line {
    flex-grow: 1;

    &:focus-visible {
      z-index: 1;
    }
  }

  > .reveal-button-container {
    display: flex;
    justify-content: end;
    align-items: center;
    height: var(--line-container-height);
    padding: 3px;
  }
}

input[readonly] {
  caret-color: transparent;
}

:host([linetype="username"]),
:host([linetype="password"]) {
  > .line-container.copied {
    background-color: transparent;

    .input-label::after {
      position: static;
      visibility: visible;
      opacity: 1;
    }

    .copy-icon {
      opacity: 0;
    }

    .check-icon {
      visibility: visible;
      opacity: 1;
    }
  }

  .copy-container {
    display: grid;
    justify-items: center;
    align-items: center;
    height: 32px;
    width: 32px;

    > .copy-icon {
      grid-column: 1;
      grid-row: 1;
      height: var(--icon-size);
      width: var(--icon-size);
      -moz-context-properties: fill;
      fill: var(--icon-color);

      @media not (prefers-reduced-motion) {
        transition: var(--copy-transition);
      }
    }

    > .check-icon {
      grid-column: 1;
      grid-row: 1;
      height: var(--icon-size);
      width: var(--icon-size);
      -moz-context-properties: fill;
      fill: var(--check-icon-color);
      opacity: 0;
      visibility: hidden;

      @media not (prefers-reduced-motion) {
        transition: var(--copy-transition);
      }
    }
  }
}

:host([alert]) .alert-icon {
  display: block;
  height: 12px;
  width: 12px;
  -moz-context-properties: fill, stroke;
  fill: var(--alert-color);
  stroke: var(--alert-color);
}

.label-container {
  display: flex;
  column-gap: var(--space-xxsmall);
  position: relative;
}

.input-label {
  display: block;
  text-transform: uppercase;
  font-size: 0.525em;
  cursor: unset;

  &::after {
    position: absolute;
    content: " " attr(data-after);
    visibility: hidden;
    opacity: 0;

    @media not (prefers-reduced-motion) {
      transition: var(--copy-transition);
    }
  }
}

.line-container {
  width: 100%;
  height: var(--line-container-height);
  border-radius: var(--inner-border-radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.input-container {
  display: flex;
  flex-direction: column;
  row-gap: var(--space-xxsmall);
  margin-inline-start: var(--space-medium);
}

.value-container {
  display: flex;
  align-items: end;
  column-gap: var(--space-small);
}

.fav-icon {
  margin: 0;
  height: var(--icon-size);
  width: var(--icon-size);
  -moz-context-properties: fill;
  fill: var(--icon-color);
}

.input-field {
  all: unset;
  display: inline-block;
  text-overflow: ellipsis;
  overflow: hidden;
  appearance: textfield;
  color: var(--input-field-color);
  width: 100%;
}
