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;

    --checkbox-color: var(--flow-ui-checkbox-color, var(--flow-ui-color-primary-500));
    --checkbox-check-color: var(--flow-ui-checkbox-check-color, var(--flow-ui-color-primary-contrast));
  }

  .checkbox {
    position: relative;
    display: inline-flex;
    width: 100%;
    align-items: flex-start;
    font-family: var(--flow-ui-control-font-family);
    font-weight: var(--flow-ui-control-font-weight);
    color: var(--flow-ui-control-label-color);
    vertical-align: middle;
    cursor: pointer;
  }

  /* Sizes */
  .checkbox--small {
    --toggle-size: var(--flow-ui-toggle-size-small);
    font-size: var(--flow-ui-control-font-size-small);
  }

  .checkbox--medium {
    --toggle-size: var(--flow-ui-toggle-size-medium);
    font-size: var(--flow-ui-control-font-size-medium);
  }

  .checkbox--large {
    --toggle-size: var(--flow-ui-toggle-size-large);
    font-size: var(--flow-ui-control-font-size-large);
  }

  .checkbox__control {
    flex: 0 0 auto;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--toggle-size);
    height: var(--toggle-size);
    border: solid var(--flow-ui-control-border-width) var(--flow-ui-control-border-color);
    border-radius: 2px;
    background-color: var(--flow-ui-control-background-color);
    color: var(--checkbox-check-color);
    transition:
      var(--flow-ui-transition-fast) border-color,
      var(--flow-ui-transition-fast) background-color,
      var(--flow-ui-transition-fast) color,
      var(--flow-ui-transition-fast) box-shadow;
  }

  .checkbox__input {
    position: absolute;
    opacity: 0;
    padding: 0;
    margin: 0;
    pointer-events: none;
  }

  .checkbox__checked-icon,
  .checkbox__indeterminate-icon {
    display: inline-flex;
    width: var(--toggle-size);
    height: var(--toggle-size);
  }

  /* Hover */
  .checkbox:not(.checkbox--checked):not(.checkbox--disabled) .checkbox__control:hover {
    border-color: var(--flow-ui-control-border-color-hover);
    background-color: var(--flow-ui-control-background-color-hover);
  }

  /* Focus */
  .checkbox:not(.checkbox--checked):not(.checkbox--disabled) .checkbox__input:focus-visible ~ .checkbox__control {
    outline: var(--flow-ui-focus-ring);
    outline-offset: var(--flow-ui-focus-ring-offset);
  }

  /* Checked/indeterminate */
  .checkbox--checked .checkbox__control,
  .checkbox--indeterminate .checkbox__control {
    border-color: var(--checkbox-color);
    background-color: var(--checkbox-color);
  }

  /* Checked/indeterminate + focus */
  .checkbox.checkbox--checked:not(.checkbox--disabled) .checkbox__input:focus-visible ~ .checkbox__control,
  .checkbox.checkbox--indeterminate:not(.checkbox--disabled) .checkbox__input:focus-visible ~ .checkbox__control {
    outline: var(--flow-ui-focus-ring);
    outline-offset: var(--flow-ui-focus-ring-offset);
  }

  /* Disabled */
  .checkbox--disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .checkbox__label {
    display: inline-block;
    flex: 1;
    color: var(--flow-ui-control-label-color);
    line-height: var(--toggle-size);
    margin-inline-start: 0.5em;
    user-select: none;
  }

  /* Reverse layout */
  .checkbox--reverse {
    flex-direction: row-reverse;
  }

  .checkbox--reverse .checkbox__label {
    margin-inline-start: 0;
    margin-inline-end: 0.5em;
  }

  :host([required]) .checkbox__label::after {
    content: var(--flow-ui-control-required-content);
    margin-inline-start: var(--flow-ui-control-required-content-offset);
  }
`;

export { styles as default };
