"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// tmp-babel/activity-log/web/ActivityLogComponent/DateFilterComponent/index.js
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
var _material = require('@mui/material');
var _xdatepickers = require('@mui/x-date-pickers');
var _AdapterLuxon = require('@mui/x-date-pickers/AdapterLuxon');
var _DatePicker = require('@mui/x-date-pickers/DatePicker');
var _jsxruntime = require('react/jsx-runtime');
function _typeof(o) {
  "@babel/helpers - typeof";
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
    return typeof o2;
  } : function(o2) {
    return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
  }, _typeof(o);
}
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e, n, i, u, a = [], f = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var DateFilterComponent = function DateFilterComponent2(_ref) {
  var createdFrom = _ref.createdFrom, createdTo = _ref.createdTo, executeRefetch = _ref.executeRefetch, onApply = _ref.onApply, onClearFilter = _ref.onClearFilter;
  var _useState = _react.useState.call(void 0, createdFrom !== null && createdFrom !== void 0 ? createdFrom : null), _useState2 = _slicedToArray(_useState, 2), tempCreatedFrom = _useState2[0], setTempCreatedFrom = _useState2[1];
  var _useState3 = _react.useState.call(void 0, createdTo !== null && createdTo !== void 0 ? createdTo : null), _useState4 = _slicedToArray(_useState3, 2), tempCreatedTo = _useState4[0], setTempCreatedTo = _useState4[1];
  var _useState5 = _react.useState.call(void 0, null), _useState6 = _slicedToArray(_useState5, 2), error = _useState6[0], setError = _useState6[1];
  var errorMessage = _react2.default.useMemo(function() {
    switch (error) {
      case "minDate":
        return "End date cannot be earlier than start date.";
      case "invalidDate":
        return "Your date is not valid";
      default:
        return "";
    }
  }, [error]);
  var handleApply = function handleApply2() {
    if (tempCreatedTo && tempCreatedFrom && tempCreatedTo < tempCreatedFrom) {
      setError("minDate");
      return;
    }
    setError(null);
    executeRefetch({
      createdFrom: tempCreatedFrom ? tempCreatedFrom.toISODate() : null,
      createdTo: tempCreatedTo ? tempCreatedTo.toISODate() : null
    });
    onApply === null || onApply === void 0 || onApply();
  };
  var handleClear = function handleClear2() {
    if (createdFrom || createdTo) {
      executeRefetch({
        createdFrom: null,
        createdTo: null
      });
    }
    setTempCreatedFrom(null);
    setTempCreatedTo(null);
    onClearFilter === null || onClearFilter === void 0 || onClearFilter();
  };
  var disableStartDate = function disableStartDate2(date) {
    return tempCreatedTo ? date > tempCreatedTo : false;
  };
  var disableEndDate = function disableEndDate2(date) {
    return tempCreatedFrom ? date < tempCreatedFrom : false;
  };
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
    display: "flex",
    gap: 2,
    flexDirection: "column",
    children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _xdatepickers.LocalizationProvider, {
      dateAdapter: _AdapterLuxon.AdapterLuxon,
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _DatePicker.DatePicker, {
        label: "Start date",
        onChange: function onChange(newValue) {
          return setTempCreatedFrom(newValue);
        },
        disableFuture: true,
        value: tempCreatedFrom,
        shouldDisableDate: disableStartDate,
        slotProps: {
          day: function day(dayProps) {
            return {
              sx: _objectSpread({}, disableStartDate(dayProps.day) && {
                backgroundColor: "error.lighter"
              })
            };
          }
        }
      }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _DatePicker.DatePicker, {
        label: "End date",
        value: tempCreatedTo,
        onChange: function onChange(newValue) {
          return setTempCreatedTo(newValue);
        },
        onError: function onError(newError) {
          return setError(newError);
        },
        disableFuture: true,
        shouldDisableDate: disableEndDate,
        slotProps: {
          textField: {
            helperText: errorMessage
          },
          day: function day(dayProps) {
            return {
              sx: _objectSpread({}, disableEndDate(dayProps.day) && {
                backgroundColor: "error.lighter"
              })
            };
          }
        }
      })]
    }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
      display: "flex",
      gap: 2,
      flexDirection: "column",
      mt: 4,
      mb: 2,
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Button, {
        onClick: handleApply,
        variant: "contained",
        color: "inherit",
        children: "Filter"
      }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Button, {
        onClick: handleClear,
        variant: "outlined",
        color: "inherit",
        children: "Clear Filter"
      })]
    })]
  });
};
var DateFilterComponent_default = DateFilterComponent;



exports.DateFilterComponent_default = DateFilterComponent_default;
//# sourceMappingURL=chunk-O62GMM6N.js.map