@import "../../settings/all";
@import "../../tools/all";
@import "../../helpers/all";

@import "../error-message/error-message";
@import "../fieldset/fieldset";
@import "../hint/hint";
@import "../label/label";

@include govuk-exports("govuk/component/checkboxes") {
  $govuk-checkboxes-size: govuk-spacing(7);
  $govuk-checkboxes-label-padding-left-right: govuk-spacing(3);

  .govuk-checkboxes__item {
    @include govuk-font($size: 19);

    display: block;
    position: relative;

    min-height: $govuk-checkboxes-size;

    margin-bottom: govuk-spacing(2);
    padding: 0 0 0 $govuk-checkboxes-size;

    clear: left;
  }

  .govuk-checkboxes__item:last-child,
  .govuk-checkboxes__item:last-of-type {
    margin-bottom: 0;
  }

  .govuk-checkboxes__input {
    position: absolute;

    z-index: 1;
    top: 0;
    left: 0;

    width: $govuk-checkboxes-size;
    height: $govuk-checkboxes-size;

    cursor: pointer;

    // IE8 doesn’t support pseudoelements, so we don’t want to hide native elements there.
    @include govuk-not-ie8 {
      margin: 0;
      opacity: 0;
    }

    // add focus outline to input element for IE8
    @include govuk-if-ie8 {
      &:focus {
        outline: $govuk-focus-width solid $govuk-focus-colour;
      }
    }
  }

  .govuk-checkboxes__label {
    display: inline-block;
    margin-bottom: 0;
    padding: 8px $govuk-checkboxes-label-padding-left-right govuk-spacing(1);
    cursor: pointer;
    // remove 300ms pause on mobile
    -ms-touch-action: manipulation;
    touch-action: manipulation;
  }

  .govuk-checkboxes__hint {
    display: block;
    padding-right: $govuk-checkboxes-label-padding-left-right;
    padding-left: $govuk-checkboxes-label-padding-left-right;
  }

  .govuk-checkboxes__input + .govuk-checkboxes__label::before {
    content: "";
    box-sizing: border-box;
    position: absolute;
    top: 0;
    left: 0;
    width: $govuk-checkboxes-size;
    height: $govuk-checkboxes-size;
    border: $govuk-border-width-form-element solid currentColor;
    background: transparent;

    // padding-bottom: 1px;
  }

  .govuk-checkboxes__input + .govuk-checkboxes__label::after {
    content: "";

    position: absolute;
    top: 11px;
    left: 9px;
    width: 18px;
    height: 7px;

    -webkit-transform: rotate(-45deg);

        -ms-transform: rotate(-45deg);

            transform: rotate(-45deg);
    border: solid;
    border-width: 0 0 $govuk-border-width $govuk-border-width;
    // Fix bug in IE11 caused by transform rotate (-45deg).
    // See: alphagov/govuk_elements/issues/518
    border-top-color: transparent;

    opacity: 0;

    background: transparent;
  }

  // Focused state
  .govuk-checkboxes__input:focus + .govuk-checkboxes__label::before {
    // Since box-shadows are removed when users customise their colours
    // We set a transparent outline that is shown instead.
    // https://accessibility.blog.gov.uk/2017/03/27/how-users-change-colours-on-websites/
    outline: $govuk-focus-width solid transparent;
    outline-offset: $govuk-focus-width;
    box-shadow: 0 0 0 $govuk-focus-width $govuk-focus-colour;
  }

  // Selected state
  .govuk-checkboxes__input:checked + .govuk-checkboxes__label::after {
    opacity: 1;
  }

  // Disabled state
  .govuk-checkboxes__input:disabled,
  .govuk-checkboxes__input:disabled + .govuk-checkboxes__label {
    cursor: default;
  }

  .govuk-checkboxes__input:disabled + .govuk-checkboxes__label {
    opacity: .5;
  }

  $conditional-border-width: $govuk-border-width-mobile;
  // Calculate the amount of padding needed to keep the border centered against the checkbox.
  $conditional-border-padding: ($govuk-checkboxes-size / 2) - ($conditional-border-width / 2);
  // Move the border centered with the checkbox
  $conditional-margin-left: $conditional-border-padding;
  // Move the contents of the conditional inline with the label
  $conditional-padding-left: $conditional-border-padding + $govuk-checkboxes-label-padding-left-right;

  .govuk-checkboxes__conditional {
    @include govuk-responsive-margin(4, "bottom");
    margin-left: $conditional-margin-left;
    padding-left: $conditional-padding-left;
    border-left: $conditional-border-width solid $govuk-border-colour;

    .js-enabled &--hidden {
      display: none;
    }

    & > :last-child {
      margin-bottom: 0;
    }
  }
}
