"use strict";

exports.__esModule = true;
exports["default"] = void 0;

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

require("./style.css");

var _SliderRange = _interopRequireDefault(require("../../components/SliderRange"));

var _Button = _interopRequireDefault(require("../../components/Button"));

var _reactSelect = _interopRequireDefault(require("react-select"));

var _reactRedux = require("react-redux");

var _main = require("../../store/rehab/main");

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

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 _extends() { _extends = Object.assign || 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); }

var colors = {
  primary25: '#f0e8ff',
  primary50: '#f0e8ff',
  primary: '#673ab7',
  neutral50: '#7b7b7b',
  neutral60: '#7b7b7b',
  neutral70: '#7b7b7b',
  neutral80: '#7b7b7b',
  neutral90: '#7b7b7b'
};
var errorMessage = 'fill the required fields';
var assessmentEvaluation = {
  painLevel: 0,
  mobility: 0,
  exerciseEffort: null
};

var EvaluationAssessment = function EvaluationAssessment(props) {
  var dispatch = (0, _reactRedux.useDispatch)();

  var _useState = (0, _react.useState)(assessmentEvaluation),
      fields = _useState[0],
      setFields = _useState[1];

  var _useState2 = (0, _react.useState)(false),
      error = _useState2[0],
      setError = _useState2[1];

  var _useSelector = (0, _reactRedux.useSelector)(function (state) {
    return state.rehab.main;
  }),
      identifier = _useSelector.identifier,
      user = _useSelector.user,
      exercisesEffort = _useSelector.exercisesEffort;

  var onSubmit = function onSubmit(e) {
    e.preventDefault();

    if (fields.exerciseEffort === null) {
      return setError(true);
    }

    dispatch((0, _main.savePatientEvaluation)(_extends({}, fields, {
      identifier: identifier,
      user: user
    })));
  }; // const [execEffort, setExecEffort] = useState(false);


  var onChangeRange = function onChangeRange(e, select) {
    var _e$target, _e$target2, _extends2;

    var name = (e === null || e === void 0 ? void 0 : (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.name) || (select === null || select === void 0 ? void 0 : select.name);
    var value = (e === null || e === void 0 ? void 0 : (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : _e$target2.value) || (e === null || e === void 0 ? void 0 : e.value);
    setFields(_extends({}, fields, (_extends2 = {}, _extends2[name] = value, _extends2)));

    if (fields.exerciseEffort != null || fields.exerciseEffort != '') {
      return setError(false);
    }
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "evaluation-assessment"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "container"
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("h1", {
    className: "evaluation-assessment-title"
  }, "Rehab Evaluation"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "evaluation-assessment-content"
  }, /*#__PURE__*/_react["default"].createElement("form", {
    className: "form",
    onSubmit: onSubmit
  }, /*#__PURE__*/_react["default"].createElement("h1", {
    className: "evaluation-assessment-subtitle"
  }, "What is your current level of pain?"), /*#__PURE__*/_react["default"].createElement(_SliderRange["default"], {
    min: -5,
    max: 5,
    step: 1,
    level1: "Better",
    level2: "No Change",
    level3: "Worse",
    className: "range-slider",
    onChange: onChangeRange,
    name: "painLevel"
  }), /*#__PURE__*/_react["default"].createElement("h1", {
    className: "evaluation-assessment-subtitle"
  }, "How is your progress?"), /*#__PURE__*/_react["default"].createElement(_SliderRange["default"], {
    min: -5,
    max: 5,
    step: 1,
    level1: "Better",
    level2: "No Change",
    level3: "Worse",
    className: "range-slider",
    onChange: onChangeRange,
    name: "mobility"
  }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("h1", {
    className: "evaluation-assessment-subtitle"
  }, "What is the effort to complete your rehab exercises?"), /*#__PURE__*/_react["default"].createElement(_reactSelect["default"], {
    name: "exerciseEffort",
    options: exercisesEffort === null || exercisesEffort === void 0 ? void 0 : exercisesEffort.map(function (exer) {
      return {
        label: exer.name,
        value: exer._id
      };
    }),
    theme: function theme(_theme) {
      return _extends({}, _theme, {
        colors: _extends({}, _theme.colors, colors)
      });
    },
    className: error ? 'custom-select-opt invalid' : 'custom-select-opt',
    onChange: onChangeRange
  })), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
    text: "Save"
  }), error && /*#__PURE__*/_react["default"].createElement("div", {
    className: "error-message"
  }, errorMessage))))));
};

var _default = EvaluationAssessment;
exports["default"] = _default;
module.exports = exports.default;