"use strict";

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

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

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

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

require("antd/dist/antd.css");

var _antd2 = require("antd");

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

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

require("./style.css");

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

// or 'antd/dist/antd.less'
// import Input from '@components/Input';
// import TextArea from '@components/TextArea';
var TextArea = _antd2.Input.TextArea;
var errorMessage = 'fill the required fields';
var RangePicker = _antd2.DatePicker.RangePicker;

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

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

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

  var onFinish = function onFinish(values) {
    setError(false);
    console.log('Success:', values);
    var objectData = {
      title: values.title,
      description: values.description,
      repetitions: values.reps,
      setsPerSessions: values.setsSession,
      setsPerDay: values.setsDay,
      frequencyPerWeek: values.frequencyWeek,
      startDate: values === null || values === void 0 ? void 0 : values.exerciseDate[0].format('YYYY-MM-DD HH:mm:ss'),
      finalDate: values === null || values === void 0 ? void 0 : values.exerciseDate[1].format('YYYY-MM-DD HH:mm:ss')
    };
    dispatch((0, _main.nextSequence)(sequence.next));
    dispatch((0, _main.updateRecordConsult)(objectData));
  };

  var onFinishFailed = function onFinishFailed(errorInfo) {
    console.log('Failed:', errorInfo);
    setError(true);
  };

  var onValuesChange = function onValuesChange() {
    setError(false);
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "record-form"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "container"
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("h1", {
    className: "record-form-title"
  }, "Record Consult"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "record-form-content"
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Form, {
    labelWrap: true,
    layout: "vertical",
    onFinish: onFinish,
    size: "large",
    onValuesChange: onValuesChange,
    onFinishFailed: onFinishFailed
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Form.Item, {
    name: "title",
    rules: [{
      required: true,
      message: ''
    }]
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Input, {
    placeholder: "Add rehab exercise title"
  })), /*#__PURE__*/_react["default"].createElement(_antd2.Form.Item, {
    name: "description"
  }, /*#__PURE__*/_react["default"].createElement(TextArea, {
    rows: 4,
    placeholder: "Description"
  })), /*#__PURE__*/_react["default"].createElement(_antd2.Row, {
    gutter: [16]
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Col, {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Form.Item, {
    name: "reps",
    rules: [{
      required: true,
      message: ''
    }]
  }, /*#__PURE__*/_react["default"].createElement(_antd2.InputNumber, {
    min: 0,
    style: {
      width: '100%'
    },
    placeholder: "Repetitions"
  }))), /*#__PURE__*/_react["default"].createElement(_antd2.Col, {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Form.Item, {
    name: "setsSession",
    rules: [{
      required: true,
      message: ''
    }]
  }, /*#__PURE__*/_react["default"].createElement(_antd2.InputNumber, {
    min: 0,
    style: {
      width: '100%'
    },
    placeholder: "Sets per session"
  }))), /*#__PURE__*/_react["default"].createElement(_antd2.Col, {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Form.Item, {
    name: "setsDay",
    rules: [{
      required: true,
      message: ''
    }]
  }, /*#__PURE__*/_react["default"].createElement(_antd2.InputNumber, {
    min: 0,
    style: {
      width: '100%'
    },
    placeholder: "Sets per day"
  }))), /*#__PURE__*/_react["default"].createElement(_antd2.Col, {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Form.Item, {
    name: "frequencyWeek",
    rules: [{
      required: true,
      message: ''
    }]
  }, /*#__PURE__*/_react["default"].createElement(_antd2.InputNumber, {
    min: 0,
    placeholder: "Frequency per week",
    style: {
      width: '100%'
    }
  }))), /*#__PURE__*/_react["default"].createElement(_antd2.Col, {
    span: 16
  }, /*#__PURE__*/_react["default"].createElement(_antd2.Form.Item, {
    name: "exerciseDate",
    rules: [{
      required: true,
      message: ''
    }]
  }, /*#__PURE__*/_react["default"].createElement(RangePicker, {
    style: {
      width: '100%'
    },
    format: "YYYY-MM-DD"
  })))), /*#__PURE__*/_react["default"].createElement(_antd2.Form.Item, null, /*#__PURE__*/_react["default"].createElement(_antd2.Button, {
    size: "large",
    htmlType: "submit",
    block: true
  }, "SAVE")), error && /*#__PURE__*/_react["default"].createElement("div", {
    className: "error-message"
  }, errorMessage))))));
};

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