import { _ as _asyncToGenerator, r as regenerator } from '../../index-qSfOyGhk.js';
import { _ as _slicedToArray } from '../../slicedToArray-BB-AwwkK.js';
import React__default, { useState } from 'react';
import { render, screen, act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import CheckboxField from '../index.js';
import useForm, { Form } from '../../use-form/index.js';
import '../../typeof-CgC7Bq6K.js';
import '../../checkbox/index.js';
import '../../extends-C4cduGrv.js';
import '../../defineProperty-CEd-kZQW.js';
import '../../objectWithoutProperties-TXwlfNxG.js';
import 'prop-types';
import 'classnames';
import '../../auto-id.esm-CjaDlg7r.js';
import '../../utils.esm-BKUEBdyY.js';
import '../../warning-s9zGJbnw.js';
import '../../_commonjsHelpers-_1FafXWI.js';
import '../../use-progress/index.js';
import '../../use-trailing-debounce/index.js';

var ExampleField = function ExampleField() {
  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      value = _useState2[0],
      setvalue = _useState2[1];

  return /*#__PURE__*/React__default.createElement(CheckboxField, {
    label: "Optimize",
    name: "optimize",
    onChange: function onChange(event) {
      return setvalue(event.target.checked);
    },
    value: value
  });
};

var ExampleFieldInForm = function ExampleFieldInForm() {
  var form = useForm({
    initialData: {
      optimize: false
    }
  });
  return /*#__PURE__*/React__default.createElement(Form, {
    form: form
  }, /*#__PURE__*/React__default.createElement(CheckboxField, {
    label: "Optimize",
    name: "optimize"
  }));
};

describe("CheckboxField", function () {
  test("using outside of a form", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
    var input;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(ExampleField, null));
            input = screen.getByLabelText("Optimize");
            expect(input.checked).toEqual(false);
            _context.next = 5;
            return act(function () {
              return userEvent.click(input);
            });

          case 5:
            expect(input.checked).toEqual(true);

          case 6:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  test("using inside of a form", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
    var input;
    return regenerator.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(ExampleFieldInForm, null));
            input = screen.getByLabelText("Optimize");
            expect(input.checked).toEqual(false);
            _context2.next = 5;
            return act(function () {
              return userEvent.click(input);
            });

          case 5:
            expect(input.checked).toEqual(true);

          case 6:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
});
