import { css } from 'lit';
import componentStyles from '../../styles/component.styles.mjs';
import formControlStyles from '../../styles/form-control.styles.mjs';

const styles = css`
  ${componentStyles}
  ${formControlStyles}

  :host {
    display: inline-block;
  }

  .form-control__input {
    padding-inline: var(--control-spacing);
  }

  .input__control {
    flex: 1;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    width: 100%;
    min-width: 0;
    height: var(--control-height);
    color: var(--flow-ui-control-color);
    border: none;
    background: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
    cursor: inherit;
    -webkit-appearance: none;
    outline: none;
  }

  .input__control::-webkit-search-decoration,
  .input__control::-webkit-search-cancel-button,
  .input__control::-webkit-search-results-button,
  .input__control::-webkit-search-results-decoration {
    -webkit-appearance: none;
  }

  .input__control:-webkit-autofill,
  .input__control:-webkit-autofill:hover,
  .input__control:-webkit-autofill:focus,
  .input__control:-webkit-autofill:active {
    box-shadow: 0 0 0 var(--flow-ui-control-height-large) var(--flow-ui-control-background-color-hover) inset !important;
    -webkit-text-fill-color: var(--flow-ui-color-primary-400);
    caret-color: var(--flow-ui-control-color);
  }

  .input--filled .input__control:-webkit-autofill,
  .input--filled .input__control:-webkit-autofill:hover,
  .input--filled .input__control:-webkit-autofill:focus,
  .input--filled .input__control:-webkit-autofill:active {
    box-shadow: 0 0 0 var(--flow-ui-control-height-large) var(--flow-ui-control-filled-background-color) inset !important;
  }

  /* Wrapper to allow display input to be sized based on its content */

  .input__wrapper {
    height: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .form-control--inline .input__wrapper {
    align-items: flex-start;
  }

  .input__sizer {
    white-space: pre;
    display: block;
    height: 0;
    overflow: hidden;
  }

  /* Placeholder */

  .input__control::placeholder {
    color: var(--flow-ui-control-placeholder-color);
    user-select: none;
  }

  /* Prefix and Suffix */

  .input__prefix,
  .input__suffix {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    cursor: default;
  }

  .input__prefix::slotted(flow-ui-icon),
  .input__suffix::slotted(flow-ui-icon) {
    color: var(--flow-ui-control-icon-color);
  }

  .input__prefix::slotted(*) {
    margin-inline-end: var(--control-spacing);
  }

  .input__suffix::slotted(*) {
    margin-inline-start: var(--control-spacing);
  }

  /* Clearable + Password Toggle */

  .input__clear,
  .input__password-toggle {
    display: inline-flex;
    padding-inline-start: var(--control-spacing);
    padding-inline-end: 0;
    align-items: center;
    justify-content: center;
    font-size: inherit;
    color: var(--flow-ui-control-icon-color);
    border: none;
    background: none;
    transition: var(--flow-ui-transition-fast) color;
    cursor: pointer;
  }

  .input__clear:hover,
  .input__password-toggle:hover {
    color: var(--flow-ui-control-icon-color-hover);
  }

  .input__clear:focus,
  .input__password-toggle:focus {
    outline: none;
  }

  .input--empty .input__clear {
    visibility: hidden;
  }

  /* Don't show the browser's password toggle in Edge */
  ::-ms-reveal {
    display: none;
  }

  /* Hide the built-in number spinner */
  .input--no-spin-buttons input[type='number']::-webkit-outer-spin-button,
  .input--no-spin-buttons input[type='number']::-webkit-inner-spin-button {
    -webkit-appearance: none;
    display: none;
  }

  .input--no-spin-buttons input[type='number'] {
    -moz-appearance: textfield;
  }

  .input__stepper-button-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-inline-start: var(--control-spacing);
  }

  .input__stepper-button::part(base) {
    padding: 0;
  }

  .form-control--small .input__stepper-button {
    --icon-size: var(--flow-ui-font-size-x-small);
  }

  .form-control--medium .input__stepper-button {
    --icon-size: var(--flow-ui-font-size-small);
  }

  .form-control--large .input__stepper-button {
    --icon-size: var(--flow-ui-font-size-medium);
  }
`;

export { styles as default };
