"use strict";

exports.__esModule = true;
exports.default = exports.useStyles = void 0;

var _react = _interopRequireDefault(require("react"));

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(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(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(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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 = (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: function cursor(props) {
        return props.readOnly ? "default" : "inherit";
      }
    },
    thumb: {
      width: theme.spacing(1.3),
      height: theme.spacing(1.3),
      backgroundColor: theme.palette.background.default,
      display: function display(props) {
        return props.readOnly ? "none" : "inherit";
      }
    },
    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),
        right: function right(props) {
          return props.readOnly && theme.spacing(0.9);
        },
        opacity: 0
      },
      "&:after": {
        content: function content(props) {
          return "\"".concat(props.formattedOffCaption, "\"");
        },
        right: theme.spacing(0.9),
        left: function left(props) {
          return props.readOnly && 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")
      }
    }
  };
});
exports.useStyles = useStyles;

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 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,
    readOnly: readOnly
  });

  var switchClasses = _objectSpread(_objectSpread({}, classes), className);

  return /*#__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"
  });
};

__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 = _default2;
exports.default = _default3;
;

(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);
})();