import { E as compilerRuntimeExports, r as reactExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { h as filtersLabelsKeys, c0 as CalendarIcon } from "./index-DfebxkL9.js";
import { F as FilterTemplate } from "./index-C6QQOvbB.js";
import { c as createStyles, W as useMediaQuery, as as DatePickerInput } from "./vendor-mantine-h0WlM2Mj.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
const useStyles = createStyles(() => ({
  container: {
    display: "flex",
    flexDirection: "column",
    width: "100%",
    "& .mantine-DatePickerInput-input": {
      borderRadius: "8px"
    },
    "& .mantine-Popover-dropdown": {
      padding: "16px"
    },
    "& .mantine-DatePickerInput-calendar": {
      width: "255px"
    }
  }
}));
const DateRangeFilter = (t0) => {
  const $ = compilerRuntimeExports.c(34);
  const {
    type,
    locale: t1,
    handleChange,
    handleFilterReset,
    activeValue,
    hideCollapse,
    maxDate
  } = t0;
  const locale = t1 === void 0 ? "ru" : t1;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  let t2;
  if ($[0] !== activeValue) {
    t2 = activeValue || [null, null];
    $[0] = activeValue;
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  const [value, setValue] = reactExports.useState(t2);
  const isMinHeight = useMediaQuery("(max-height: 515px)");
  let t3;
  if ($[2] !== handleChange || $[3] !== handleFilterReset || $[4] !== type) {
    t3 = (valueString) => {
      const value_0 = valueString.map(_temp);
      setValue(value_0);
      if (value_0.every(_temp2)) {
        handleChange({
          Type: type,
          value: value_0
        });
      } else {
        if (value_0.every(_temp3)) {
          handleFilterReset(type);
        }
      }
    };
    $[2] = handleChange;
    $[3] = handleFilterReset;
    $[4] = type;
    $[5] = t3;
  } else {
    t3 = $[5];
  }
  const handleChangeDate = t3;
  let t4;
  if ($[6] !== handleFilterReset) {
    t4 = (value_1) => {
      setValue([null, null]);
      handleFilterReset(value_1);
    };
    $[6] = handleFilterReset;
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  const resetDate = t4;
  const t5 = `filters.${filtersLabelsKeys[type]}`;
  let t6;
  if ($[8] !== t || $[9] !== t5) {
    t6 = t(t5);
    $[8] = t;
    $[9] = t5;
    $[10] = t6;
  } else {
    t6 = $[10];
  }
  let t7;
  if ($[11] !== activeValue) {
    t7 = activeValue == null ? void 0 : activeValue.some(_temp4);
    $[11] = activeValue;
    $[12] = t7;
  } else {
    t7 = $[12];
  }
  const t8 = isMinHeight ? "right" : "bottom-start";
  let t9;
  if ($[13] !== t8) {
    t9 = {
      zIndex: 1400,
      withinPortal: false,
      position: t8
    };
    $[13] = t8;
    $[14] = t9;
  } else {
    t9 = $[14];
  }
  const t10 = classes.container;
  let t11;
  if ($[15] !== t) {
    t11 = t("users.chooseRange");
    $[15] = t;
    $[16] = t11;
  } else {
    t11 = $[16];
  }
  let t12;
  if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsx(CalendarIcon, {});
    $[17] = t12;
  } else {
    t12 = $[17];
  }
  let t13;
  if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
    t13 = {
      day: {
        "&[data-today]": {
          backgroundColor: "rgba(206, 234, 255, 0.65)"
        }
      }
    };
    $[18] = t13;
  } else {
    t13 = $[18];
  }
  let t14;
  if ($[19] !== classes.container || $[20] !== handleChangeDate || $[21] !== locale || $[22] !== maxDate || $[23] !== t11 || $[24] !== t9 || $[25] !== value) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsx(DatePickerInput, { popoverProps: t9, className: t10, type: "range", clearable: true, placeholder: t11, value, onChange: handleChangeDate, leftSection: t12, locale, maxDate, allowSingleDateInRange: true, styles: t13 });
    $[19] = classes.container;
    $[20] = handleChangeDate;
    $[21] = locale;
    $[22] = maxDate;
    $[23] = t11;
    $[24] = t9;
    $[25] = value;
    $[26] = t14;
  } else {
    t14 = $[26];
  }
  let t15;
  if ($[27] !== hideCollapse || $[28] !== resetDate || $[29] !== t14 || $[30] !== t6 || $[31] !== t7 || $[32] !== type) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsx(FilterTemplate, { label: t6, handleFilterReset: resetDate, isActive: t7, type, hideCollapse, children: t14 });
    $[27] = hideCollapse;
    $[28] = resetDate;
    $[29] = t14;
    $[30] = t6;
    $[31] = t7;
    $[32] = type;
    $[33] = t15;
  } else {
    t15 = $[33];
  }
  return t15;
};
function _temp(date) {
  return date ? new Date(date) : null;
}
function _temp2(item_0) {
  return item_0 !== null;
}
function _temp3(item) {
  return item === null;
}
function _temp4(item_1) {
  return item_1 !== null;
}
export {
  DateRangeFilter as D
};
//# sourceMappingURL=index-_NgMYV3i.js.map
