import _uniqueId from "lodash/fp/uniqueId";
import _noop from "lodash/fp/noop";
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import getClassState from '../../util/get-class-state';
import style from './style.css';
const InputSwitch = props => {
  const {
    title,
    name,
    id,
    value,
    disabled,
    onChange = _noop,
    description,
    modified = false,
    theme = 'default',
    titlePosition = 'left',
    details = '',
    requiredSelection = false,
    'data-name': dataName,
    'aria-labelledby': ariaLabelledBy,
    'aria-label': ariaLabel
  } = props;
  const idSwitch = id || _uniqueId('input-switch-');
  const isDisabled = disabled ? 'disabled' : '';
  const handleChange = useMemo(() => e => onChange(e.target.checked), [onChange]);
  const titleView = title ? /*#__PURE__*/React.createElement("span", {
    id: `title-view-${dataName}`,
    className: style.title
  }, `${title} `, ' ') : null;
  const descriptionView = description ? /*#__PURE__*/React.createElement("div", {
    className: style.description
  }, description) : null;
  const getClass = () => {
    switch (theme) {
      case 'coorpmanager':
        return {
          defaultClass: style.coorpmanager,
          modifiedClass: style.coorpmanagerModified
        };
      case 'mooc':
        return {
          defaultClass: style.partielUncheck,
          modifiedClass: style.coorpmanagerModified
        };
      default:
        return {
          defaultClass: style.defaultStyle,
          modifiedClass: style.modified
        };
    }
  };
  const {
    defaultClass,
    modifiedClass
  } = getClass();
  const className = getClassState(defaultClass, modifiedClass, null, modified);
  return /*#__PURE__*/React.createElement("div", {
    className: className,
    "data-name": `switch-input-${theme}${dataName}`
  }, titlePosition === 'left' ? titleView : null, /*#__PURE__*/React.createElement("div", {
    className: requiredSelection ? style.requiredSelection : null
  }, /*#__PURE__*/React.createElement("div", {
    className: style.btnSwitchContainer
  }, /*#__PURE__*/React.createElement("input", _extends({}, ariaLabelledBy ? {
    'aria-labelledby': ariaLabelledBy
  } : {}, title ? {
    'aria-labelledby': `title-view-${dataName}`
  } : {}, ariaLabel && !ariaLabelledBy && !title ? {
    'aria-label': ariaLabel
  } : {}, {
    type: "checkbox",
    id: idSwitch,
    name: name,
    onChange: handleChange,
    checked: value,
    disabled: isDisabled,
    className: style.checkbox,
    "aria-labelledby": ariaLabelledBy
  })), /*#__PURE__*/React.createElement("label", {
    htmlFor: idSwitch,
    "data-name": "input-switch-label",
    tabIndex: 0,
    "aria-label": ariaLabel,
    title: ariaLabel
  }))), /*#__PURE__*/React.createElement("div", {
    className: !details ? style.alignedTextContainer : null
  }, titlePosition === 'right' ? titleView : null, details ? /*#__PURE__*/React.createElement("div", {
    className: style.detailsTxt
  }, details) : null), descriptionView);
};
InputSwitch.propTypes = process.env.NODE_ENV !== "production" ? {
  title: PropTypes.string,
  name: PropTypes.string,
  id: PropTypes.string,
  value: PropTypes.bool,
  disabled: PropTypes.bool,
  onChange: PropTypes.func,
  description: PropTypes.string,
  'aria-labelledby': PropTypes.string,
  'aria-label': PropTypes.string,
  modified: PropTypes.bool,
  titlePosition: PropTypes.oneOf(['right', 'left']),
  theme: PropTypes.oneOf(['default', 'coorpmanager', 'mooc']),
  details: PropTypes.string,
  'data-name': PropTypes.string,
  requiredSelection: PropTypes.bool
} : {};
export default InputSwitch;
//# sourceMappingURL=index.js.map