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

import React from 'react';
import PropTypes from 'prop-types';
import { DateTime } from 'luxon';
import DatePicker, { DATE_FORMATS } from './DatePicker';
const DATE_FORMAT = DATE_FORMATS.full;
/**
 * A relative version of the date picker.
 *
 * Selectable range is determined as days relative to
 * an anchor date (defaults to 'today' e.g. interview date,
 * when not set).
 */

const RelativeDatePicker = ({
  parameters = {},
  ...rest
}) => {
  const anchor = parameters.anchor ? DateTime.fromISO(parameters.anchor) : DateTime.local();
  const min = anchor.minus({
    days: parameters.before || 180
  }).toFormat(DATE_FORMAT);
  const max = anchor.plus({
    days: parameters.after || 0
  }).toFormat(DATE_FORMAT);
  const newParameters = {
    min,
    max
  }; // eslint-disable-next-line react/jsx-props-no-spreading

  return /*#__PURE__*/React.createElement(DatePicker, _extends({}, rest, {
    parameters: newParameters
  }));
};

RelativeDatePicker.propTypes = {
  parameters: PropTypes.object
};
RelativeDatePicker.defaultProps = {
  parameters: {}
};
export default RelativeDatePicker;