import styled from "styled-components";
import {
  whiteBackground,
  blueDark600,
  grayLight300,
  grayLight400,
  blueLighter,
  BodyText,
} from "../constants";

interface CustomCheckProps {
  disabled?: boolean;
}

export const CustomCheck = styled.div<CustomCheckProps>`
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  padding: 0;
  [type="checkbox"]:checked,
  [type="checkbox"]:not(:checked),
  [type="radio"]:checked,
  [type="radio"]:not(:checked) {
    position: absolute;
    left: -9999px;
  }
  [type="radio"][disabled] + label {
    cursor: not-allowed;
    color: ${(props) => `${props.disabled ? grayLight300 : grayLight400}`};
  }
  [type="checkbox"]:checked + label,
  [type="checkbox"]:not(:checked) + label,
  [type="radio"]:checked + label,
  [type="radio"]:not(:checked) + label {
    position: relative;
    padding-left: 24px;
    cursor: pointer;
    display: inline-block;
    ${BodyText}
    color: ${(props) => `${props.disabled ? grayLight300 : grayLight400}`};
  }
  [type="checkbox"]:checked + label a,
  [type="checkbox"]:not(:checked) + label a,
  [type="radio"]:checked + label a,
  [type="radio"]:not(:checked) + label a {
    ${BodyText}
    color: ${(props) => `${props.disabled ? grayLight300 : grayLight400}`};
  }
  [type="checkbox"]:checked + label:before,
  [type="checkbox"]:not(:checked) + label:before,
  [type="radio"]:checked + label:before,
  [type="radio"]:not(:checked) + label:before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 17px;
    height: 17px;
    background: ${whiteBackground};
    border: 1px solid ${blueDark600};
  }
  [type="checkbox"]:checked + label:after,
  [type="checkbox"]:not(:checked) + label:after,
  [type="radio"]:checked + label:after,
  [type="radio"]:not(:checked) + label:after {
    content: "";
    width: 13px;
    height: 13px;
    background: ${blueDark600};
    position: absolute;
    top: 2px;
    left: 2px;
    -webkit-transition: all 0.2s ease;
    transition: all 0.2s ease;
    border-radius: 1px;
  }
  [type="checkbox"]:not(:checked) + label:after,
  [type="radio"]:not(:checked) + label:after {
    opacity: 0;
    -webkit-transform: scale(0);
    transform: scale(0);
  }
  [type="checkbox"]:checked + label:after,
  [type="radio"]:checked + label:after {
    opacity: 1;
    -webkit-transform: scale(1);
    transform: scale(1);
  }
  [type="radio"]:checked + label:before,
  [type="radio"]:not(:checked) + label:before,
  [type="radio"]:checked + label:after {
    border-radius: 20px;
  }
  [type="radio"]:disabled + label:before,
  [type="checkbox"]:disabled + label:before {
    cursor: not-allowed;
    color: ${grayLight300};
    border-color: ${blueLighter};
  }
  [type="radio"]:disabled + label:after,
  [type="checkbox"]:disabled + label:after {
    opacity: 1;
    -webkit-transform: scale(1);
    transform: scale(1);
    content: "";
    width: 13px;
    height: 13px;
    background: ${blueLighter};
    position: absolute;
    top: 2px;
    left: 2px;
    -webkit-transition: all 0.2s ease;
    transition: all 0.2s ease;
    border-radius: 1px;
  }
  [type="radio"]:disabled + label:after {
    border-radius: 50%;
  }
`;
