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: block;
  }

  /** The popup */
  .datepicker {
    flex: 1 1 auto;
    display: inline-flex;
    width: 100%;
    position: relative;
    vertical-align: middle;
    --arrow-color: var(--flow-ui-color-neutral-300);
  }

  .datepicker::part(popup) {
    z-index: var(--flow-ui-z-index-dropdown);
  }

  .datepicker[data-current-placement^='top']::part(popup) {
    transform-origin: bottom;
  }

  .datepicker[data-current-placement^='bottom']::part(popup) {
    transform-origin: top;
  }

  /* Combobox */
  .datepicker__combobox {
    flex: 1;
    display: flex;
    width: 100%;
    min-width: 0;
    position: relative;
    align-items: center;
    justify-content: start;
    font-family: var(--flow-ui-control-font-family);
    font-weight: var(--flow-ui-control-font-weight);
    letter-spacing: var(--flow-ui-control-letter-spacing);
    vertical-align: middle;
    overflow: hidden;
    cursor: pointer;
    transition:
      var(--flow-ui-transition-fast) color,
      var(--flow-ui-transition-fast) border,
      var(--flow-ui-transition-fast) box-shadow,
      var(--flow-ui-transition-fast) background-color;
  }

  .datepicker__display-input {
    position: relative;
    width: 100%;
    font: inherit;
    border: none;
    background: none;
    color: var(--flow-ui-control-color);
    cursor: inherit;
    overflow: hidden;
    padding: 0;
    margin: 0;
    -webkit-appearance: none;
  }

  .datepicker:not(.datepicker--disabled):hover .datepicker__display-input {
    color: var(--flow-ui-control-color-hover);
  }

  .datepicker__display-input:focus {
    outline: none;
  }

  /* Wrapper to allow display input to be sized based on its content */
  .input__wrapper {
    flex: 1;
    display: grid;
  }

  .form-control--inline .input__wrapper {
    grid-template-columns: min-content;
  }

  /* For measuring width of displayed option text */
  .input__sizer {
    white-space: pre;
    height: 0;
    overflow: hidden;
  }

  .datepicker__value-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    opacity: 0;
    z-index: -1;
  }

  .datepicker--standard.datepicker--disabled .datepicker__combobox {
    background-color: var(--flow-ui-control-background-color-disabled);
    border-color: var(--flow-ui-control-border-color-disabled);
    color: var(--flow-ui-control-color-disabled);
    opacity: 0.5;
    cursor: not-allowed;
    outline: none;
  }

  .datepicker--standard:not(.datepicker--disabled).datepicker--open .datepicker__combobox,
  .datepicker--standard:not(.datepicker--disabled).datepicker--focused .datepicker__combobox {
    background-color: var(--flow-ui-control-background-color-focus);
    border-color: var(--flow-ui-control-border-color-focus);
    box-shadow: 0 0 0 var(--flow-ui-focus-ring-width) var(--flow-ui-control-focus-ring-color);
  }

  .datepicker--filled .datepicker__combobox {
    border: none;
    background-color: var(--flow-ui-control-filled-background-color);
    color: var(--flow-ui-control-color);
  }

  .datepicker--filled:hover:not(.datepicker--disabled) .datepicker__combobox {
    background-color: var(--flow-ui-control-filled-background-color-hover);
  }

  .datepicker--filled.datepicker--disabled .datepicker__combobox {
    background-color: var(--flow-ui-control-filled-background-color-disabled);
    opacity: 0.5;
    cursor: not-allowed;
  }

  .datepicker--filled:not(.datepicker--disabled).datepicker--open .datepicker__combobox,
  .datepicker--filled:not(.datepicker--disabled).datepicker--focused .datepicker__combobox {
    background-color: var(--flow-ui-control-filled-background-color-focus);
    outline: var(--flow-ui-focus-ring);
  }

  /* Sizes */
  .datepicker--small .datepicker__combobox {
    border-radius: var(--flow-ui-control-border-radius-small);
    font-size: var(--flow-ui-control-font-size-small);
    min-height: var(--flow-ui-control-height-small);
    padding-block: 0;
    padding-inline: var(--flow-ui-control-spacing-small);
  }

  .datepicker--small .datepicker__clear {
    margin-inline-start: var(--flow-ui-control-spacing-small);
  }

  .datepicker--small .datepicker__prefix::slotted(*) {
    margin-inline-end: var(--flow-ui-control-spacing-small);
  }

  .datepicker--medium .datepicker__combobox {
    border-radius: var(--flow-ui-control-border-radius-medium);
    font-size: var(--flow-ui-control-font-size-medium);
    min-height: var(--flow-ui-control-height-medium);
    padding-block: 0;
    padding-inline: var(--flow-ui-control-spacing-medium);
  }

  .datepicker--medium .datepicker__clear {
    margin-inline-start: var(--flow-ui-control-spacing-medium);
  }

  .datepicker--medium .datepicker__prefix::slotted(*) {
    margin-inline-end: var(--flow-ui-control-spacing-medium);
  }

  .datepicker--large .datepicker__combobox {
    border-radius: var(--flow-ui-control-border-radius-large);
    font-size: var(--flow-ui-control-font-size-large);
    min-height: var(--flow-ui-control-height-large);
    padding-block: 0;
    padding-inline: var(--flow-ui-control-spacing-large);
  }

  .datepicker--large .datepicker__clear {
    margin-inline-start: var(--flow-ui-control-spacing-large);
  }

  .datepicker--large .datepicker__prefix::slotted(*) {
    margin-inline-end: var(--flow-ui-control-spacing-large);
  }

  /* Pills */
  .datepicker--pill.datepicker--small .datepicker__combobox {
    border-radius: var(--flow-ui-control-height-small);
  }

  .datepicker--pill.datepicker--medium .datepicker__combobox {
    border-radius: var(--flow-ui-control-height-medium);
  }

  .datepicker--pill.datepicker--large .datepicker__combobox {
    border-radius: var(--flow-ui-control-height-large);
  }

  /* Prefix */
  .datepicker__prefix {
    flex: 0;
    display: inline-flex;
    align-items: center;
    color: var(--flow-ui-control-placeholder-color);
  }

  /* Clear button */
  .datepicker__clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: inherit;
    color: var(--flow-ui-control-icon-color);
    border: none;
    background: none;
    padding: 0;
    transition: var(--flow-ui-transition-fast) color;
    cursor: pointer;
  }

  .datepicker__clear:hover {
    color: var(--flow-ui-control-icon-color-hover);
  }

  .datepicker__clear:focus {
    outline: none;
  }

  /* Mode icon (calendar/clock) */
  .datepicker__mode-icon {
    color: var(--flow-ui-color-neutral-800);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    margin-inline-start: var(--flow-ui-spacing-small);
  }

  .datepicker--open .datepicker__mode-icon {
    color: var(--flow-ui-color-primary-500);
  }

  /* Calendar container */
  .datepicker__calendar-container {
    display: block;
    position: relative;
    font-family: var(--flow-ui-font-sans);
    font-size: var(--flow-ui-font-size-medium);
    font-weight: var(--flow-ui-font-weight-normal);
    box-shadow: var(--flow-ui-shadow-large);
    background: var(--flow-ui-calendar-background-color);
    border: solid var(--flow-ui-menu-border-width) var(--flow-ui-menu-border-color);
    border-radius: var(--flow-ui-border-radius-medium);
    padding: var(--flow-ui-spacing-x-small);
    overflow: auto;
    overscroll-behavior: none;

    /* Make sure it adheres to the popup's auto size */
    max-width: var(--auto-size-available-width);
    max-height: var(--auto-size-available-height);
  }
`;

export { styles as default };
