/* Lightning Design System 0.9.1 */
// Copyright (c) 2015, salesforce.com, inc. All rights reserved.

// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



.#{$css-prefix}checkbox {
  display: inline-block;

  .#{$css-prefix}checkbox--faux {
    @include square($square-icon-medium-content);
    display: inline-block;
    position: relative;
    vertical-align: middle;
    border: $border-width-thin solid $color-border-input;
    border-radius: $border-radius-small;
    background: $color-background-input;
    transition: border $duration-quickly linear, background-color $duration-quickly linear;
  }

  .#{$css-prefix}form-element__label {
    display: inline;
    vertical-align: middle;
    font-size: $font-size-medium;
  }

  [type="checkbox"] {
    @include square(1px);
    border: 0;
    clip: rect(0 0 0 0);
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;

    .#{$css-prefix}form-element & ~ .#{$css-prefix}checkbox--faux {
      margin-right: $spacing-x-small;
    }

    &:checked ~ .#{$css-prefix}checkbox--faux {

      &:after {
        display: block;
        content: '';
        height: ($square-icon-x-small-content / 2);
        width: $square-icon-x-small-content;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate3d(-50%, -50%, 0) rotate(-45deg);
        border-bottom: $border-width-thick solid $color-brand;
        border-left: $border-width-thick solid $color-brand;
      }
    }

    &:focus {

      ~ .#{$css-prefix}checkbox--faux {
        content: '';
        border-color: $color-border-input-active;
        box-shadow: $shadow-button-focus;
      }

      &:checked ~ .#{$css-prefix}checkbox--faux {
        border-color: $color-border-input-active;
        background-color: $color-background-input;
      }
    }

    &[disabled] {

      ~ .#{$css-prefix}checkbox--faux {
        background-color: $color-background-input-disabled;
        border-color: $color-border-input-disabled;
      }

      ~ .#{$css-prefix}checkbox--faux:after {
        border-color: $color-background-input;
      }
    }

    .#{$css-prefix}has-error & {

      ~ .#{$css-prefix}checkbox--faux {
          border-color: $color-border-error;
          border-width: $border-width-thick;
      }

      &:checked ~ .#{$css-prefix}checkbox--faux {
        border-color: $color-border-error;
        background-color: $color-background-input;
      }

      &:checked ~ .#{$css-prefix}checkbox--faux:after {
        border-color: $color-background-error;
      }
    }

    .#{$css-prefix}is-required > & ~ .#{$css-prefix}checkbox--faux:after {
      content: '*';
      color: $color-text-error;
      position: absolute;
      left: ($spacing-x-small * -1);
    }
  }
}
