<template>
  <!-- Checkbox groups MUST be wrapped in a <fieldset> and <legend> tag -->
  <div class="ui-checkbox d-flex">
    <input type="checkbox" aria-checked="false" :name="checkboxName" :id="buttonID" :tabindex="tabIndex" :aria-required="isRequired" />
    <label class="d-flex align-items-center" :for="buttonID">
      <p v-if="checkboxLabel" class="m-0">{{checkboxLabel}}</p>
      <span v-if="screenReaderOnlyText" class="sr-only">{{screenReaderOnlyText}}</span>
    </label>
  </div>
</template>

<script>
export default {
  name: "checkbox",
  props: {
    checkboxName: String,
    buttonID: String,
    tabIndex: Number,
    checkboxLabel: String,
    screenReaderOnlyText: String,
    isRequired: Boolean
  }
};
</script>

<style lang="scss">
.ui-checkbox {
  position: relative;
  input[type='checkbox'] {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    + label {
      display: block;
      position: relative;
    }
    + label::before {
      content: '';
      position: relative;
      display: inline-block;
      margin-right: 10px;
      width: 16px;
      height: 16px;
      background: white;
      border: 1px solid $gray-500;
      border-radius: 2px;
    }
    &:checked + label::before {
      background: $blue;
    }
    &:checked + label::after {
      content: '';
      position: absolute;
      top: 8px;
      left: 2px;
      border-left: 2px solid $white;
      border-bottom: 2px solid $white;
      height: 6px;
      width: 12px;
      transform: rotate(-45deg);
    }
    &:hover + label::before {
      box-shadow: 0 0 0 4px $blue-100;
    }
    &:focus + label::before {
      box-shadow: 0 0 0 2px $blue;
    }
    &:focus:checked + label::before {
      box-shadow: 0 0 0 2px transparent;
    }
    &:disabled + label {
      color: $gray-200;
    }
    &:disabled + label::before {
      background: $gray-200;
    }
  }
}
</style>
