import { css } from 'lit';

export default css`
:host {
  display: inline-flex;
  flex-direction: column;
  vertical-align: top;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  cursor: text;

  --_active-indicator-color: var(--md-sys-color-on-surface-variant);
  --_active-indicator-height: 1px;
  --_focus-active-indicator-color: var(--md-sys-color-primary, #6750a4);
  --_focus-active-indicator-height: 2px;

  min-width: 200px;
}

.surface {
  height: 56px;
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--md-sys-shape-corner-extra-small-top);
  cursor: inherit;
}

.container {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-color: var(--md-sys-color-surface-variant);
  border-radius: inherit;
}

.content {
  height: inherit;
  display: flex;
  align-items: center;
  justify-content: start;
  box-sizing: border-box;
  position: relative;
  z-index: 2;
  flex: 1;
  cursor: inherit;
}

.body {
  flex: 1;
  overflow: hidden;
  padding-top: 1em;
  box-sizing: border-box;
  position: relative;
  cursor: inherit;
}

.label {
  color: var(--md-sys-color-on-surface-variant);
  max-width: 100%;
  pointer-events: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 3;

  position: absolute;
  transform: translateY(-1.35rem) scale(0.8);
  transform-origin: left center;
  top: 50%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  font-family: var(--md-sys-typescale-body-large-font-family-name);
  font-style: var(--md-sys-typescale-body-large-font-family-style);
  font-weight: var(--md-sys-typescale-body-large-font-weight);
  font-size: var(--md-sys-typescale-body-large-font-size);
  letter-spacing: var(--md-sys-typescale-body-large-tracking, 0.031rem);
  line-height: var(--md-sys-typescale-body-large-height);
  text-transform: var(--md-sys-typescale-body-large-text-transform);
  text-decoration: var(--md-sys-typescale-body-large-text-decoration);
}

.labelResting .label {
  transform: translateY(-50%) scale(1);
}

:host(:focus-within) .label {
  color: var(--md-sys-color-primary);
}

.input {
  caret-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-surface);
  height: 24px; /* ??? */
  flex: 1; /* ??? */
  white-space: nowrap;
  overflow: hidden;
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  margin: 0;
  width: 1px;
  cursor: inherit;

  font-family: var(--md-sys-typescale-body-large-font-family-name);
  font-style: var(--md-sys-typescale-body-large-font-family-style);
  font-weight: var(--md-sys-typescale-body-large-font-weight);
  font-size: var(--md-sys-typescale-body-large-font-size);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  line-height: var(--md-sys-typescale-body-large-height);
  text-transform: var(--md-sys-typescale-body-large-text-transform);
  text-decoration: var(--md-sys-typescale-body-large-text-decoration);
}

.input:-webkit-autofill,
.input:autofill {
  background-color: transparent !important;
}

.start,
.body,
.end {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: start;
}

.start {
  width: 16px;
  min-width: 16px;
}

.start.prefixed {
  width: 24px;
  min-width: 24px;
  margin-left: 12px;
  margin-right: 16px;
}

.end {
  width: 16px;
  min-width: 16px;
}

.end.suffixed {
  width: 24px;
  min-width: 24px;
  margin-right: 12px;
  padding-right: 12px;
  margin-left: 16px;
}

.end ::slotted(*),
.start ::slotted(*) {
  cursor: default;
}

.highlight {
  inset: auto 0px 0px;
  pointer-events: none;
  position: absolute;
  width: 100%;
  z-index: 4;
}

.highlight::before {
  content: "";
  border-bottom: 1px solid var(--md-sys-color-on-surface-variant);
  inset: auto 0px 0px;
  position: absolute;
}

.highlight::after {
  content: "";
  border-bottom-color: var(--md-sys-color-primary);
  border-bottom-width: 2px;
  border-bottom-style: solid;
  opacity: 0;
  transform: scaleX(0);
  transform-origin: center center;

  transition: 
    opacity 150ms cubic-bezier(0.4, 0, 0.2, 1) 0s, 
    transform 150ms cubic-bezier(0.4, 0, 0.2, 1) 150ms;

  position: absolute;
  inset: auto 0px 0px;
}

:host(:focus-within) .highlight::after {
  opacity: 1;
  transform: scaleX(1);
}

.labelHidden .label {
  display: none;
}

.labelHidden .body {
  padding-top: 0;
}

.supporting-text {
  padding-top: 4px;
  color: var(--md-sys-color-on-surface-variant);
  font-family: var(--md-sys-typescale-body-medium-font-family-name);
  font-style: var(--md-sys-typescale-body-medium-font-family-style);
  font-weight: var(--md-sys-typescale-body-medium-font-weight);
  font-size: var(--md-sys-typescale-body-medium-font-size);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  line-height: var(--md-sys-typescale-body-medium-height);
  text-transform: var(--md-sys-typescale-body-medium-text-transform);
  text-decoration: var(--md-sys-typescale-body-medium-text-decoration);
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
}

.supporting-text-start {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 16px;
}

.container::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  background-color: var(--md-sys-color-on-surface-variant);
  transition: opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

:host(:hover) .container::before {
  opacity: var(--md-sys-state-hover-state-layer-opacity);
}

:host([disabled]) {
  pointer-events: none;
}

:host([disabled]) .container {
  background-color: var(--md-sys-color-on-surface);
  opacity: .04;
}

:host([disabled]) .highlight::before {
  border-bottom-color: var(--md-sys-color-on-surface);
  opacity: .38;
}

:host([disabled]) .label,
:host([disabled]) .input,
:host([disabled]) .end ::slotted(*),
:host([disabled]) .start ::slotted(*) {
  color: var(--md-sys-color-on-surface);
  opacity: .38;
}

:host([invalid]) .highlight::before {
  border-bottom-color: var(--md-sys-color-error);
}

:host([invalid]) .label,
:host([invalid]) .supporting-text,
:host([invalid]) .end ::slotted(*) {
  color: var(--md-sys-color-error);
}

:host([invalid]:hover) .highlight::before {
  border-bottom-color: var(--md-sys-color-on-error-container);
}

:host([invalid]:hover) .label,
:host([invalid]:hover) .end ::slotted(*) {
  color: var(--md-sys-color-on-error-container);
}
`;
