// @author    : Adarsh Pastakia
// @version   : 5.0.0
// @copyright : 2019
// @license   : MIT

.ui-option {
  display: inline-block;

  &__group {
    align-items: center;
    display: grid;
    grid-auto-rows: 2rem;
    grid-column: 1;
    grid-column-gap: 4px;
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    justify-items: start;
  }

  &__toggle {
    border-radius: 1em;
    cursor: pointer;
    font-size: 1rem;
    margin: 0 4px;
    opacity: 0.9;
    overflow: hidden;
    position: relative;
    width: 2em;
    --toggle-on: "\00A0\2758";
    --toggle-off: "O";

    &::before {
      content: var(--toggle-off);
      display: block;
      font-size: 0.8em;
      line-height: 1;
      margin: auto;
      padding: 2px;
      position: absolute;
      width: 100%;
      @include property-prefix(text-align, end);
    }

    &::after {
      border-radius: 1em;
      content: "";
      display: block;
      height: calc(1em - 2px);
      left: 0;
      margin: 1px;
      position: relative;
      transition: left 0.2s;
      width: calc(1em - 2px);
    }
  }

  &__control {
    align-items: center;
    display: grid;
    grid-column-gap: 2px;
    grid-template-columns: auto 1fr;
    position: relative;

    > span {
      font-size: 0.95em;
      line-height: 1.5rem;
      white-space: nowrap;
      @include ellipsis();

      &:empty {
        display: none;
      }
    }

    > .ui-icon {
      font-size: 1.25rem;
    }

    > input {
      @include position(absolute, 0);
      cursor: pointer;
      opacity: 0;
      z-index: 2;

      ~ .ui-icon:first-of-type {
        display: block;
      }

      ~ .ui-icon:last-of-type {
        display: none;
      }

      ~ .ui-icon:nth-of-type(2) {
        display: none;
      }

      &:focus ~ .ui-option__toggle {
        border-radius: 1em;
        overflow: hidden;
      }

      &[data-checked="__2__"] {
        ~ .ui-icon:first-of-type {
          display: none;
        }

        ~ .ui-icon:last-of-type {
          display: none;
        }

        ~ .ui-icon:nth-of-type(2) {
          display: block;
        }
      }

      &:checked {
        ~ .ui-icon:first-of-type {
          display: none;
        }

        ~ .ui-icon:last-of-type {
          display: block;
        }

        ~ .ui-option__toggle {

          &::before {
            content: var(--toggle-on);
            @include property-prefix(text-align, start);
          }

          &::after {
            left: calc(100% - 1em);
          }

          @at-root [dir="rtl"] &::after {
            left: calc(-100% + 1em);
          }
        }
      }
    }
  }

  &[data-disabled="true"] {
    cursor: not-allowed;

    label {
      opacity: 0.4;
      pointer-events: none;
    }
  }
}
