// Copyright (C) 2018 The Trustees of Indiana University
// SPDX-License-Identifier: BSD-3-Clause

@use '../core' as *;
@use 'sass:math';

.#{$prefix}-checkbox {
  display: inline-block;
  padding-left: $spacing-lg;
  position: relative;

  input[type='checkbox'] {
    cursor: pointer;
    height: $spacing-md;
    left: 0;
    margin: 0;
    opacity: 0;
    position: absolute;
    top: 0;
    width: $spacing-lg;
  }

  &--sr-only-label {
    padding-left: $spacing-md;
  }

  &--sr-only-label input[type='checkbox'] {
    width: $spacing-md;
  }

  &--sr-only-label input[type='checkbox'] ~ label {
    height: 0;
    overflow: hidden;
    padding: 0;
    width: 0;
  }

  input[type='checkbox'] ~ label {
    cursor: pointer;
    display: inline-block;
    line-height: $line-height-base;
  }

  input[type='checkbox'] ~ label::before {
    background-color: $color-white-base;
    border: math.div($spacing-xxs, 2) solid $color-black-300;
    border-radius: math.div($spacing-xxs, 2);
    content: '';
    display: inline-block;
    height: $spacing-sm;
    left: math.div($spacing-xxs, 2);
    position: absolute;
    top: math.div($spacing-xxs, 2);
    width: $spacing-sm;
  }

  input[type='checkbox']:checked ~ label::before,
  input[type='checkbox']:indeterminate ~ label::before {
    background-color: $color-blue-500;
    background-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" fill="%23ffffff" viewBox="0 0 16 16"><path d="m14.914 4-9.47 9.47L1.09 8.393 2.608 7.09l2.948 3.44L13.5 2.585 14.914 4Z"></path></svg>');
    background-position: 50% 50%;
    background-repeat: no-repeat;
    border-color: $color-blue-500;
  }

  input[type='checkbox']:indeterminate ~ label::before {
    background-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" fill="%23ffffff" viewBox="0 0 16 16" id="rvt-icon-minus"><path d="M15 9H1V7h14v2Z"></path></svg>');
  }

  input[type='checkbox']:focus ~ label::before {
    box-shadow:
      0 0 0 math.div($spacing-xxs, 2) $color-white-base,
      0 0 0 $spacing-xxs $color-blue-400;
  }

  input[type='checkbox']:disabled {
    cursor: default;
  }

  input[type='checkbox']:disabled ~ label {
    color: $color-black-400;
    cursor: default;
  }

  input[type='checkbox']:disabled ~ label::before {
    background-color: $color-black-100;
    border-color: $color-black-300;
  }

  &__description {
    color: $color-black-400;
    display: block;
    font-size: $ts-14;
  }
}
