"use strict";

exports.__esModule = true;
exports.useStyles = exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Switch = _interopRequireDefault(require("@material-ui/core/Switch"));
var _styles = require("@material-ui/core/styles");
var _SwitchProps = _interopRequireWildcard(require("./SwitchProps"));
var _reactIntl = require("react-intl");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var useStyles = exports.useStyles = (0, _styles.makeStyles)(function (theme) {
  return {
    root: {
      width: theme.spacing(6.4),
      height: theme.spacing(1.7),
      padding: 0
    },
    switchBase: {
      padding: theme.spacing(0.2),
      border: "none",
      "&:hover, &:active": {
        backgroundColor: "unset",
        boxShadow: "unset"
      }
    },
    input: {
      left: "-250%",
      width: "600%",
      cursor: "inherit"
    },
    inputReadOnly: {
      cursor: "default"
    },
    thumb: {
      width: theme.spacing(1.3),
      height: theme.spacing(1.3),
      backgroundColor: theme.palette.background.default,
      display: "inherit"
    },
    thumbReadOnly: {
      display: "none"
    },
    track: {
      backgroundColor: theme.palette.grey.borders,
      opacity: "1 !important",
      borderRadius: "20px",
      position: "relative",
      "&:before, &:after": {
        display: "inline-block",
        position: "absolute",
        top: "50%",
        transform: "translateY(-50%)",
        textAlign: "center",
        fontSize: theme.spacing(1)
      },
      "&:before": {
        content: function content(props) {
          return "\"".concat(props.formattedOnCaption, "\"");
        },
        left: theme.spacing(0.9),
        opacity: 0
      },
      "&:after": {
        content: function content(props) {
          return "\"".concat(props.formattedOffCaption, "\"");
        },
        right: theme.spacing(0.9)
      }
    },
    trackReadOnly: {
      "&:before": {
        right: theme.spacing(0.9)
      },
      "&:after": {
        left: theme.spacing(0.9)
      }
    },
    checked: {
      "&$switchBase": {
        transform: "translateX(".concat(theme.spacing(4.7), ")")
      },
      "& + $track": {
        backgroundColor: theme.palette.primary.main,
        color: theme.palette.background.default,
        "&:before": {
          opacity: 1
        },
        "&:after": {
          opacity: 0
        }
      }
    },
    disabled: {
      "& + $track": {
        backgroundColor: "".concat(theme.palette.grey.borders, " !important")
      }
    },
    container: {
      display: "flex",
      flexDirection: "column"
    },
    errorText: {
      marginTop: theme.spacing(0.5),
      color: theme.palette.error.main,
      fontSize: theme.typography.fieldLabelSize,
      float: "left"
    }
  };
});
var Switch = function Switch(_ref) {
  var switchProps = _ref.switchProps;
  var _useIntl = (0, _reactIntl.useIntl)(),
    formatMessage = _useIntl.formatMessage;
  if ((0, _SwitchProps.isSwitchProps)(switchProps) === false) {
    throw new TypeError("switchProps property is not of type SwitchProps");
  }
  var update = switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.update);
  var value = (switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.value)) || false;
  var onCaption = switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.onCaption);
  var offCaption = switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.offCaption);
  var error = switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.error);
  var disabled = (switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.disabled)) || false;
  var readOnly = switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.readOnly);
  var className = (switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.className)) || "";
  var metadata = (switchProps == null ? void 0 : switchProps.get(_SwitchProps.default.propNames.metadata)) || null;
  var formattedOnCaption = onCaption != null ? formatMessage(onCaption) : "";
  var formattedOffCaption = offCaption != null ? formatMessage(offCaption) : "";
  var classes = useStyles({
    formattedOnCaption: formattedOnCaption,
    formattedOffCaption: formattedOffCaption
  });
  var switchClasses = _objectSpread({
    root: classes.root,
    switchBase: classes.switchBase,
    input: (0, _classnames.default)(classes.input, _defineProperty({}, classes.inputReadOnly, readOnly)),
    thumb: (0, _classnames.default)(classes.thumb, _defineProperty({}, classes.thumbReadOnly, readOnly)),
    track: (0, _classnames.default)(classes.track, _defineProperty({}, classes.trackReadOnly, readOnly)),
    checked: classes.checked,
    disabled: classes.disabled
  }, className);
  var switchComponent = /*#__PURE__*/_react.default.createElement(_Switch.default, {
    disabled: disabled,
    classes: switchClasses,
    checked: value,
    onChange: function onChange(e) {
      return !readOnly ? update(e.target.checked, metadata) : null;
    },
    color: "primary"
  });
  return error && /*#__PURE__*/_react.default.createElement("div", {
    className: classes.container
  }, switchComponent, /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _classnames.default)(classes.errorText)
  }, error)) || switchComponent;
};
__signature__(Switch, "useIntl{{ formatMessage }}\nuseStyles{classes}", function () {
  return [_reactIntl.useIntl, useStyles];
});
__signature__(Switch, "useIntl{{ formatMessage }}\nuseStyles{classes}", function () {
  return [_reactIntl.useIntl, useStyles];
});
var _default = Switch;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Switch.js");
  reactHotLoader.register(Switch, "Switch", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Switch.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Switch.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useStyles, "useStyles", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Switch.js");
  reactHotLoader.register(Switch, "Switch", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Switch.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Switch.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();