"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkXCPYE27Djs = require('./chunk-XCPYE27D.js');


var _chunkY32DFJ3Gjs = require('./chunk-Y32DFJ3G.js');


var _chunk3MZLT2YIjs = require('./chunk-3MZLT2YI.js');


var _chunk25CJDQG6js = require('./chunk-25CJDQG6.js');


var _chunkRYSJFIPTjs = require('./chunk-RYSJFIPT.js');

// tmp-babel/activity-log/web/ActivityLogComponent/index.js
var _react = require('react');
var _inputs = require('@baseapp-frontend/design-system/components/web/inputs');
var _material = require('@mui/material');
var _reacthookform = require('react-hook-form');
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 ActivityLogComponent = function ActivityLogComponent2(_ref) {
  var queryRef = _ref.queryRef, _ref$LogGroups = _ref.LogGroups, LogGroups = _ref$LogGroups === void 0 ? _chunkXCPYE27Djs.LogGroups_default : _ref$LogGroups, LogGroupsProps = _ref.LogGroupsProps;
  var _useState = _react.useState.call(void 0, {
    createdFrom: null,
    createdTo: null,
    userName: "",
    count: 10,
    cursor: null
  }), _useState2 = _slicedToArray(_useState, 2), fetchParameters = _useState2[0], setFetchParameters = _useState2[1];
  var _useActivityLogs = _chunkRYSJFIPTjs.useActivityLogs.call(void 0, queryRef), logGroups = _useActivityLogs.logGroups, loadNext = _useActivityLogs.loadNext, hasNext = _useActivityLogs.hasNext, isLoadingNext = _useActivityLogs.isLoadingNext, refetch = _useActivityLogs.refetch;
  var _useTransition = _react.useTransition.call(void 0, ), _useTransition2 = _slicedToArray(_useTransition, 2), isPending = _useTransition2[0], startTransition = _useTransition2[1];
  var _useState3 = _react.useState.call(void 0, ["All"]), _useState4 = _slicedToArray(_useState3, 2), selectedFilters = _useState4[0], setSelectedFilters = _useState4[1];
  var _useForm = _reacthookform.useForm.call(void 0, {
    defaultValues: {
      search: ""
    }
  }), control = _useForm.control, reset = _useForm.reset, watch = _useForm.watch;
  var searchValue = watch("search");
  var executeRefetch = function executeRefetch2(updatedParameters) {
    var newFetchParameters = _objectSpread(_objectSpread({}, fetchParameters), updatedParameters);
    setFetchParameters(newFetchParameters);
    startTransition(function() {
      refetch(newFetchParameters, {
        fetchPolicy: "store-and-network"
      });
    });
  };
  var handleSearchClear = function handleSearchClear2() {
    startTransition(function() {
      reset();
      executeRefetch({
        userName: ""
      });
    });
  };
  var handleSearchChange = function handleSearchChange2(e) {
    var value = e.target.value || "";
    startTransition(function() {
      executeRefetch({
        userName: value
      });
    });
  };
  var emptyLogsList = logGroups.length === 0;
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Box, {
    p: 2,
    justifyContent: "center",
    minWidth: "100%",
    display: "flex",
    alignItems: "center",
    children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
      justifyContent: "center",
      maxWidth: 600,
      width: "100%",
      mx: "auto",
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
        component: "h4",
        variant: "h4",
        mb: 4,
        children: "Activity Log"
      }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _inputs.Searchbar, {
        placeholder: "Search by user",
        name: "search",
        control,
        onChange: handleSearchChange,
        onClear: handleSearchClear,
        isPending
      }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.Box, {
        display: "flex",
        mt: 2,
        mb: 2,
        flexDirection: "row",
        gap: 2,
        children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkY32DFJ3Gjs.DateFilterChip_default, {
          fetchParameters,
          executeRefetch
        }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk3MZLT2YIjs.EventFilterChip_default, {
          options: ["All", "Comments", "Reactions", "Posts"],
          selectedOptions: selectedFilters,
          onChange: setSelectedFilters
        })]
      }), !isPending && searchValue && emptyLogsList && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk25CJDQG6js.SearchNotFoundState_default, {}), !isPending && (fetchParameters.createdFrom != null || fetchParameters.createdTo != null) && emptyLogsList && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk25CJDQG6js.SearchNotFoundState_default, {
        message: "No results found for the selected date range."
      }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, LogGroups, _objectSpread({
        logGroups,
        loadNext,
        hasNext,
        isLoadingNext
      }, LogGroupsProps))]
    })
  });
};
var ActivityLogComponent_default = ActivityLogComponent;



exports.ActivityLogComponent_default = ActivityLogComponent_default;
//# sourceMappingURL=chunk-N4KRK34L.js.map