import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import { useEffect, useState } from 'react';
import classNames from 'classnames';
import './index.css';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export var FcrSwitch = function FcrSwitch(_ref) {
  var _labels$on, _labels$off;
  var labels = _ref.labels,
    value = _ref.value,
    _ref$onChange = _ref.onChange,
    onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
  var _useState = useState(value),
    _useState2 = _slicedToArray(_useState, 2),
    toggle = _useState2[0],
    setToggle = _useState2[1];
  var cls = classNames('fcr-switch', {
    'fcr-switch--on': toggle,
    'fcr-switch--off': !toggle
  });
  var handleClick = function handleClick() {
    setToggle(!toggle);
    onChange(!toggle);
  };
  useEffect(function () {
    setToggle(value);
  }, [value]);
  return /*#__PURE__*/_jsxs("div", {
    className: cls,
    onClick: handleClick,
    children: [/*#__PURE__*/_jsxs("div", {
      className: "fcr-switch__labels",
      children: [/*#__PURE__*/_jsx("span", {
        children: (_labels$on = labels === null || labels === void 0 ? void 0 : labels.on) !== null && _labels$on !== void 0 ? _labels$on : 'ON'
      }), /*#__PURE__*/_jsx("span", {
        children: (_labels$off = labels === null || labels === void 0 ? void 0 : labels.off) !== null && _labels$off !== void 0 ? _labels$off : 'OFF'
      })]
    }), /*#__PURE__*/_jsx("div", {
      className: "fcr-switch__slider"
    })]
  });
};