'use strict';

var clsx = require('clsx');
var React = require('react');
var contexts = require('../inputs/contexts.js');
var jsxRuntime = require('react/jsx-runtime');

const CheckboxButton = /*#__PURE__*/React.forwardRef(function CheckboxButton({
  checked,
  indeterminate = false,
  className,
  disabled,
  onChange,
  ...rest
}, reference) {
  const inputAttributes = contexts.useInputAttributes();
  const internalRef = React.useRef(null);
  React.useImperativeHandle(reference, () => internalRef.current ?? {});
  React.useEffect(() => {
    if (internalRef.current) {
      // eslint-disable-next-line functional/immutable-data, @typescript-eslint/no-unsafe-assignment
      internalRef.current.indeterminate = indeterminate;
    }
  }, [indeterminate, reference]);
  return /*#__PURE__*/jsxRuntime.jsxs("span", {
    className: clsx.clsx('np-checkbox-button', className, disabled && 'disabled'),
    children: [/*#__PURE__*/jsxRuntime.jsx("input", {
      ...inputAttributes,
      ...rest,
      ref: reference ?? internalRef,
      type: "checkbox",
      disabled: disabled,
      checked: checked,
      onChange: onChange
    }), /*#__PURE__*/jsxRuntime.jsxs("span", {
      className: "tw-checkbox-button",
      children: [/*#__PURE__*/jsxRuntime.jsx("span", {
        className: "tw-checkbox-check"
      }), /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "np-tw-checkbox-indeterminate"
      })]
    })]
  });
});

module.exports = CheckboxButton;
//# sourceMappingURL=CheckboxButton.js.map
