"use strict";

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

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

require("./style.css");

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

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

var _Checkbox = _interopRequireDefault(require("../../components/Checkbox"));

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

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

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

var _preAssessments = require("../../store/rom/preAssessments");

var _weeklyAssessments = require("../../store/rom/weeklyAssessments");

var _md = require("react-icons/md");

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 WeeklyAssessment = function WeeklyAssessment(props) {
  var dispatch = (0, _reactRedux.useDispatch)();

  var _useState = (0, _react.useState)(false),
      newPain = _useState[0],
      setNewPain = _useState[1];

  var _useSelector = (0, _reactRedux.useSelector)(function (state) {
    return {
      identifier: state.rom.main.identifier,
      user: state.rom.main.user,
      lastSession: state.rom.main.lastSession,
      exercisesFrequency: state.rom.weeklyAssessments.exercisesFrequency,
      exercisesEffort: state.rom.weeklyAssessments.exercisesEffort,
      painScale: state.rom.weeklyAssessments.painScale,
      bodyPointsFromLastSession: state.rom.preAssessments.bodyPointsFromLastSession
    };
  }),
      identifier = _useSelector.identifier,
      user = _useSelector.user,
      lastSession = _useSelector.lastSession,
      exercisesFrequency = _useSelector.exercisesFrequency,
      exercisesEffort = _useSelector.exercisesEffort,
      painScale = _useSelector.painScale,
      bodyPointsFromLastSession = _useSelector.bodyPointsFromLastSession;

  (0, _react.useEffect)(function () {
    dispatch((0, _preAssessments.getLastPreAssessments)({
      identifier: identifier,
      session: lastSession === null || lastSession === void 0 ? void 0 : lastSession.id
    }));
    dispatch((0, _weeklyAssessments.getWeeklyAssessmentsOptions)());
  }, []);

  var closeWeeklyAssessment = function closeWeeklyAssessment(e) {
    e.stopPropagation();
    dispatch((0, _main.goToWeeklyAssessment)({
      isOpened: false
    }));
  };

  var onPreAssessment = function onPreAssessment() {
    dispatch((0, _main.goToAssessment)());
  };

  var handleChange = function handleChange(e, action) {
    // action receive from SELECT
    var name = action ? action.name : e.target.name;
    var value = action ? e.value : e.target.value;
    dispatch((0, _weeklyAssessments.updatePainScale)({
      name: name,
      value: value
    }));
  };

  var handleChangePainLevel = function handleChangePainLevel(bodyPoint, value) {
    dispatch((0, _weeklyAssessments.updateBodyPointsPainLevel)({
      bodyPoint: bodyPoint,
      value: value
    }));
  };

  var sendForm = function sendForm(e) {
    e.preventDefault();
    console.log({}); // PASSAR o POINT ID

    dispatch((0, _weeklyAssessments.saveWeeklyAssessments)(_extends({
      identifier: identifier,
      user: user
    }, painScale)));
    closeWeeklyAssessment(e);
  };

  var exerciseFrequencyValue = exercisesFrequency.find(function (val) {
    return val._id === painScale.exerciseFrequency;
  }) || null;

  if (exerciseFrequencyValue) {
    exerciseFrequencyValue = {
      value: exerciseFrequencyValue._id,
      label: exerciseFrequencyValue.name
    };
  }

  var exerciseEffortValue = exercisesEffort.find(function (val) {
    return val._id === painScale.exerciseEffort;
  }) || null;

  if (exerciseEffortValue) {
    exerciseEffortValue = {
      value: exerciseEffortValue._id,
      label: exerciseEffortValue.name
    };
  }

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "weekly-assessment"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "container"
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("h1", {
    className: "weekly-assessment-title"
  }, "Weekly Assessment"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "pre-assessment-content"
  }, /*#__PURE__*/_react["default"].createElement("form", {
    onSubmit: sendForm,
    className: "form"
  }, /*#__PURE__*/_react["default"].createElement("h1", {
    className: "weekly-assessment-subtitle"
  }, "Do you have any new pain areas to report ", /*#__PURE__*/_react["default"].createElement("br", null), "(besides what is listed below)?"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "checkbox-label-no"
  }, "No"), /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
    className: "new-pain",
    newPain: true,
    onChange: function onChange(e) {
      return setNewPain(!newPain);
    },
    value: newPain
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: "checkbox-label-yes"
  }, "Yes"), newPain && /*#__PURE__*/_react["default"].createElement("div", {
    className: "message-box"
  }, /*#__PURE__*/_react["default"].createElement("p", null, "Please record this in the Pain Assessment before continuing."), /*#__PURE__*/_react["default"].createElement("button", {
    className: "btn-solid-purpple",
    onClick: onPreAssessment
  }, "CONTINUE"), /*#__PURE__*/_react["default"].createElement("button", {
    className: "btn-solid-green"
  }, "Skip")), /*#__PURE__*/_react["default"].createElement("h1", {
    className: "weekly-assessment-subtitle"
  }, "What is your current level of pain?"), bodyPointsFromLastSession.map(function (point, index) {
    var pain = painScale.painLevel.find(function (data) {
      return data.bodyPoint === point.bodyPoint._id;
    });
    return /*#__PURE__*/_react["default"].createElement(_SliderRange["default"], {
      key: point._id + "-" + index,
      onChange: function onChange(e) {
        e.preventDefault();
        handleChangePainLevel(point.bodyPoint._id, e.target.value);
      },
      value: (pain === null || pain === void 0 ? void 0 : pain.value) || point.painLevel,
      min: 0,
      max: 10,
      step: 1,
      label: point.bodyPoint.name,
      level1: "Minimal",
      level2: "Constant",
      level3: "Extreme",
      className: "range-slider"
    });
  }), /*#__PURE__*/_react["default"].createElement("h1", {
    className: "weekly-assessment-subtitle"
  }, "How are your symptoms this week?"), /*#__PURE__*/_react["default"].createElement(_SliderRange["default"], {
    onChange: handleChange,
    value: painScale.symptoms,
    name: "symptoms",
    min: 0,
    max: 10,
    step: 1,
    level1: "Better",
    level2: "No change",
    level3: "Worse",
    className: "range-slider",
    hideLabel: true
  }), /*#__PURE__*/_react["default"].createElement("h1", {
    className: "weekly-assessment-subtitle"
  }, "How often are you following your recommended rehab exercises?"), /*#__PURE__*/_react["default"].createElement(_reactSelect["default"], {
    onChange: handleChange,
    value: exerciseFrequencyValue,
    name: "exerciseFrequency",
    options: exercisesFrequency.map(function (val) {
      return {
        value: val._id,
        label: val.name
      };
    }),
    theme: function theme(_theme) {
      return _extends({}, _theme, {
        colors: _extends({}, _theme.colors, colors)
      });
    }
  }), painScale.exerciseFrequency !== 'havent-started' && /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("h1", {
    className: "weekly-assessment-subtitle"
  }, "What is the effort to complete your rehab exercises?"), /*#__PURE__*/_react["default"].createElement(_reactSelect["default"], {
    onChange: handleChange,
    value: exerciseEffortValue,
    name: "exerciseEffort",
    options: exercisesEffort.map(function (val) {
      return {
        value: val._id,
        label: val.name
      };
    }),
    theme: function theme(_theme2) {
      return _extends({}, _theme2, {
        colors: _extends({}, _theme2.colors, colors)
      });
    }
  })), /*#__PURE__*/_react["default"].createElement("h1", {
    className: "weekly-assessment-subtitle"
  }, "Any serious health concerns we should be aware of?"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "checkbox-label-no"
  }, "No"), /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], {
    name: "healthConcerns",
    onChange: handleChange,
    value: painScale.healthConcerns
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: "checkbox-label-yes"
  }, "Yes"), /*#__PURE__*/_react["default"].createElement("h1", {
    className: "weekly-assessment-warning"
  }, "If you\u2019re experiencing a health emergency contact 911 immediately."), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
    text: "Save",
    type: "submit"
  })), /*#__PURE__*/_react["default"].createElement("button", {
    className: "btn-outline btn-close",
    onClick: closeWeeklyAssessment
  }, /*#__PURE__*/_react["default"].createElement(_md.MdClose, {
    size: "30px"
  }))))));
};

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