function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import React, { useState } from 'react';
import Switch, { SwitchControlled } from './Switch';
export default function SwitchConsumer(props) {
  let isControlledByParent = props.onToggle;
  let swichComponent;

  if (isControlledByParent) {
    let [stateChecked, setChecked] = useState(props.checked);
    swichComponent = /*#__PURE__*/React.createElement(Switch, _extends({}, props, {
      checked: stateChecked,
      onToggle: () => {
        console.log('Inside Switch controlled by parent ');
        setChecked(!stateChecked);
      }
    }));
  } else {
    swichComponent = /*#__PURE__*/React.createElement(SwitchControlled, _extends({}, props, {
      checked: props.checked,
      onChange: value => console.log('from SwitchControlled', value)
    }));
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "composer"
  }, swichComponent);
}