import "core-js/modules/es.symbol.js";
import "core-js/modules/es.array.filter.js";
import "core-js/modules/es.array.for-each.js";
import "core-js/modules/es.array.push.js";
import "core-js/modules/es.object.define-properties.js";
import "core-js/modules/es.object.define-property.js";
import "core-js/modules/es.object.get-own-property-descriptor.js";
import "core-js/modules/es.object.get-own-property-descriptors.js";
import "core-js/modules/es.object.keys.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/esnext.iterator.constructor.js";
import "core-js/modules/esnext.iterator.filter.js";
import "core-js/modules/esnext.iterator.for-each.js";
import "core-js/modules/web.dom-collections.for-each.js";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["label", "onChange", "styleType", "size", "indeterminate", "style", "checkIconAlignRight"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { useEffect, useRef, useState } from 'react';
import './index.css';
import classnames from 'classnames';
import { FcrIcon } from '../icon';
import { FcrIconType } from '../icon/type';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var FcrCheckbox = function FcrCheckbox(props) {
  var label = props.label,
    onChange = props.onChange,
    _props$styleType = props.styleType,
    styleType = _props$styleType === void 0 ? 'brand' : _props$styleType,
    _props$size = props.size,
    size = _props$size === void 0 ? 'medium' : _props$size,
    indeterminate = props.indeterminate,
    style = props.style,
    _props$checkIconAlign = props.checkIconAlignRight,
    checkIconAlignRight = _props$checkIconAlign === void 0 ? false : _props$checkIconAlign,
    inputProps = _objectWithoutProperties(props, _excluded);
  var cls = classnames('fcr-checkbox', "fcr-checkbox-".concat(styleType), {
    'fcr-checkbox-s': size === 'small',
    'fcr-checkbox-check-icon-align-right': checkIconAlignRight
  });
  var _useState = useState(inputProps.checked || false),
    _useState2 = _slicedToArray(_useState, 2),
    checked = _useState2[0],
    setChecked = _useState2[1];
  var checkboxRef = useRef(null);
  useEffect(function () {
    setChecked(inputProps.checked || false);
  }, [inputProps.checked]);
  return /*#__PURE__*/_jsxs("label", {
    className: cls,
    style: _objectSpread({}, style),
    children: [/*#__PURE__*/_jsxs("span", {
      className: "fcr-checkbox-input-wrapper",
      onClick: function onClick(e) {
        if (checkboxRef.current) {
          var currentChecked = checkboxRef.current.checked;
          onChange === null || onChange === void 0 || onChange(!currentChecked);
          setChecked(!currentChecked);
        }
      },
      children: [/*#__PURE__*/_jsx("input", _objectSpread(_objectSpread({}, inputProps), {}, {
        checked: inputProps.checked,
        ref: checkboxRef,
        type: "checkbox",
        onChange: function onChange(e) {},
        onClick: function onClick(e) {
          // prevent the second event from firing
          e.stopPropagation();
        }
      })), /*#__PURE__*/_jsxs("span", {
        className: classnames('fcr-btn-click-effect fcr-checkbox-inner', {
          'fcr-checkbox-inner-indeterminate': indeterminate && !checked
        }),
        children: [indeterminate && !checked && /*#__PURE__*/_jsx(FcrIcon, {
          className: "fcr-checkbox-input-indeterminate",
          type: FcrIconType.FCR_CHEXBOX_INDETERMINATE,
          size: size === 'small' ? 8 : 12,
          colors: {
            iconPrimary: styleType === 'brand' ? 'var(--fcr_ui_scene_white10)' : 'var(--fcr_ui_scene_ramp_brand6)'
          }
        }), /*#__PURE__*/_jsx(FcrIcon, {
          type: FcrIconType.FCR_CHECKBOX_CHECK,
          size: size === 'small' ? 8 : 12,
          colors: {
            iconPrimary: styleType === 'brand' ? 'var(--fcr_ui_scene_white10)' : 'var(--fcr_ui_scene_icontext1)'
          }
        })]
      })]
    }), label && /*#__PURE__*/_jsx("span", {
      className: "fcr-checkbox-label",
      onClick: function onClick(e) {
        onChange === null || onChange === void 0 || onChange(!checked);
        setChecked(!checked);
      },
      children: label
    })]
  });
};