import { E as compilerRuntimeExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { W as Ws, b as gq } from "./vendor-icons-xWhXK_Ui.js";
import { I as IFiltersEnumType, O as themeColors } from "./index-DfebxkL9.js";
import { c as createStyles, W as useMediaQuery, b as Box, O as Badge, h as ActionIcon, U as UnstyledButton, q as Popover } from "./vendor-mantine-h0WlM2Mj.js";
import { D as DateRangeFilter } from "./index-_NgMYV3i.js";
import { S as SearchFilter } from "./index-C6QQOvbB.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
const useStyles$1 = createStyles((theme) => ({
  filterHeader: {
    display: "flex",
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "center",
    backgroundColor: "#F2F4F7",
    padding: "4px, 20px, 4px, 20px",
    height: "32px",
    gap: 0,
    borderRadius: "54px",
    fontWeight: 400,
    color: "var(--mantine-colors-black)"
  },
  menuButton: {
    display: "flex",
    alignItems: "center",
    justifyContent: "center"
  },
  badgeContainer: {
    flexDirection: "row",
    display: "flex",
    justifyContent: "center",
    alignItems: "center",
    marginLeft: "12px"
  },
  badge: {
    textTransform: "none",
    fontSize: "12px",
    fontWeight: 400,
    lineHeight: "18px",
    marginRight: theme.spacing.xs,
    borderRadius: "16px",
    padding: `0px 6px`
  },
  menu: {
    height: "180px",
    marginBottom: "10px"
  },
  dropdownContainer: {
    padding: theme.spacing.sm
  },
  withoutNumber: {
    backgroundColor: theme.colors.mainBlue[9],
    fontSize: "10px",
    lineHeight: "18px",
    marginRight: theme.spacing.xs,
    borderRadius: "50%",
    padding: 0,
    width: "18px",
    height: "18px"
  }
}));
const FilterBadge = (t0) => {
  const $ = compilerRuntimeExports.c(25);
  const {
    filterMenu,
    handleFilterReset,
    activeIds,
    filterType,
    children
  } = t0;
  const {
    classes
  } = useStyles$1();
  const isMinHeight = useMediaQuery("(max-height: 515px)");
  let t1;
  if ($[0] !== handleFilterReset) {
    t1 = (e, type) => {
      e.stopPropagation();
      handleFilterReset(type);
    };
    $[0] = handleFilterReset;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const onHandleFilterReset = t1;
  const t2 = isMinHeight ? "right" : "bottom-start";
  let t3;
  if ($[2] !== activeIds || $[3] !== classes.badge || $[4] !== classes.badgeContainer || $[5] !== classes.withoutNumber || $[6] !== filterMenu || $[7] !== filterType || $[8] !== onHandleFilterReset) {
    t3 = (activeIds == null ? void 0 : activeIds.length) > 0 && /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.badgeContainer, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Badge, { className: filterType === IFiltersEnumType.DateOfCreateFilter ? classes.withoutNumber : classes.badge, variant: "filled", children: filterType === IFiltersEnumType.DateOfCreateFilter ? " " : activeIds.length }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { size: 24, onClick: (e_0) => onHandleFilterReset(e_0, filterMenu.Type), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Ws, { size: 16, color: themeColors.brandGray[0] }) })
    ] });
    $[2] = activeIds;
    $[3] = classes.badge;
    $[4] = classes.badgeContainer;
    $[5] = classes.withoutNumber;
    $[6] = filterMenu;
    $[7] = filterType;
    $[8] = onHandleFilterReset;
    $[9] = t3;
  } else {
    t3 = $[9];
  }
  const t4 = filterMenu == null ? void 0 : filterMenu.label;
  let t5;
  if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsx(gq, { size: 18 });
    $[10] = t5;
  } else {
    t5 = $[10];
  }
  let t6;
  if ($[11] !== classes.menuButton || $[12] !== t4) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsxs(UnstyledButton, { className: classes.menuButton, children: [
      t4,
      " ",
      t5
    ] });
    $[11] = classes.menuButton;
    $[12] = t4;
    $[13] = t6;
  } else {
    t6 = $[13];
  }
  let t7;
  if ($[14] !== classes.filterHeader || $[15] !== t3 || $[16] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Popover.Target, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Badge, { variant: "transparent", color: "gray", className: classes.filterHeader, rightSection: t3, children: t6 }) });
    $[14] = classes.filterHeader;
    $[15] = t3;
    $[16] = t6;
    $[17] = t7;
  } else {
    t7 = $[17];
  }
  let t8;
  if ($[18] !== children || $[19] !== classes.dropdownContainer) {
    t8 = /* @__PURE__ */ jsxRuntimeExports.jsx(Popover.Dropdown, { className: classes.dropdownContainer, children });
    $[18] = children;
    $[19] = classes.dropdownContainer;
    $[20] = t8;
  } else {
    t8 = $[20];
  }
  let t9;
  if ($[21] !== t2 || $[22] !== t7 || $[23] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Popover, { width: "auto", zIndex: 1400, position: t2, children: [
      t7,
      t8
    ] });
    $[21] = t2;
    $[22] = t7;
    $[23] = t8;
    $[24] = t9;
  } else {
    t9 = $[24];
  }
  return t9;
};
const useStyles = createStyles(() => ({
  filtersListWrapper: {
    display: "flex",
    justifyContent: "flex-start",
    backgroundColor: "white",
    gap: "20px"
  }
}));
const FilterList = (t0) => {
  const $ = compilerRuntimeExports.c(22);
  const {
    filtersMenuList,
    activeFilters,
    onFilterChange,
    onFilterReset,
    onLoadData
  } = t0;
  const {
    i18n
  } = useTranslation();
  const {
    classes
  } = useStyles();
  let t1;
  if ($[0] !== activeFilters || $[1] !== onFilterChange) {
    t1 = (t22) => {
      const {
        Type,
        value
      } = t22;
      let typeFilters = activeFilters[Type] ? [...activeFilters[Type]] : [];
      if (Array.isArray(value)) {
        if (value.some(_temp)) {
          typeFilters = [];
        } else {
          typeFilters = value;
        }
      } else {
        if (typeFilters.some((el) => +el === +value)) {
          typeFilters = typeFilters.filter((val) => +val !== +value);
        } else {
          typeFilters.push(value);
        }
      }
      onFilterChange({
        ...activeFilters,
        [Type]: typeFilters
      });
    };
    $[0] = activeFilters;
    $[1] = onFilterChange;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const handleFilterChange = t1;
  let t2;
  if ($[3] !== activeFilters || $[4] !== onFilterReset) {
    t2 = (type) => {
      const updatedFilters = {
        ...activeFilters
      };
      delete updatedFilters[type];
      onFilterReset(updatedFilters);
    };
    $[3] = activeFilters;
    $[4] = onFilterReset;
    $[5] = t2;
  } else {
    t2 = $[5];
  }
  const handleFilterReset = t2;
  const t3 = classes.filtersListWrapper;
  let t4;
  if ($[6] !== activeFilters || $[7] !== filtersMenuList || $[8] !== handleFilterChange || $[9] !== handleFilterReset || $[10] !== i18n || $[11] !== onLoadData) {
    let t52;
    if ($[13] !== activeFilters || $[14] !== handleFilterChange || $[15] !== handleFilterReset || $[16] !== i18n || $[17] !== onLoadData) {
      t52 = (filterMenu, index) => {
        const {
          Type: filterType
        } = filterMenu;
        const activeIds = activeFilters[filterType];
        return /* @__PURE__ */ jsxRuntimeExports.jsx(FilterBadge, { filterMenu, handleFilterReset, activeIds, filterType: filterMenu == null ? void 0 : filterMenu.Type, children: filterType === IFiltersEnumType.DateOfCreateFilter ? /* @__PURE__ */ jsxRuntimeExports.jsx(DateRangeFilter, { type: filterType, handleChange: handleFilterChange, handleFilterReset, hideCollapse: true, activeValue: activeIds, maxDate: /* @__PURE__ */ new Date(), locale: i18n.language }) : /* @__PURE__ */ jsxRuntimeExports.jsx(SearchFilter, { handleFilterReset, activeIds, filterType: filterMenu == null ? void 0 : filterMenu.Type, label: filterMenu == null ? void 0 : filterMenu.label, list: filterMenu == null ? void 0 : filterMenu.Items, hideCollapse: true, handleFilterChange, handleLoadData: onLoadData }) }, (filterMenu == null ? void 0 : filterMenu.label) + index);
      };
      $[13] = activeFilters;
      $[14] = handleFilterChange;
      $[15] = handleFilterReset;
      $[16] = i18n;
      $[17] = onLoadData;
      $[18] = t52;
    } else {
      t52 = $[18];
    }
    t4 = filtersMenuList.map(t52);
    $[6] = activeFilters;
    $[7] = filtersMenuList;
    $[8] = handleFilterChange;
    $[9] = handleFilterReset;
    $[10] = i18n;
    $[11] = onLoadData;
    $[12] = t4;
  } else {
    t4 = $[12];
  }
  let t5;
  if ($[19] !== classes.filtersListWrapper || $[20] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: t3, py: "sm", children: t4 });
    $[19] = classes.filtersListWrapper;
    $[20] = t4;
    $[21] = t5;
  } else {
    t5 = $[21];
  }
  return t5;
};
function _temp(item) {
  return item === null;
}
export {
  FilterList as F
};
//# sourceMappingURL=index-CPnWygUh.js.map
