import { E as compilerRuntimeExports, r as reactExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { c as createStyles, as as DatePickerInput } from "./vendor-mantine-h0WlM2Mj.js";
import "./ru-Bush41s2.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
const useStyles = createStyles((theme) => ({
  date: {
    "& .mantine-DatePickerInput-input": {
      borderRadius: "8px",
      border: "1px solid #D0D5DD"
    },
    "& .mantine-DatePickerInput-label": {
      color: theme.colors.brandGray[0],
      fontSize: "12px",
      fontWeight: 400
    }
  }
}));
const DatePicker = (t0) => {
  var _a, _b, _c, _d;
  const $ = compilerRuntimeExports.c(30);
  const {
    form,
    fieldName,
    className,
    disabled,
    label,
    placeholder,
    withAsterisk,
    clearable: t1
  } = t0;
  const clearable = t1 === void 0 ? false : t1;
  const {
    i18n
  } = useTranslation();
  const {
    classes,
    cx
  } = useStyles();
  const [key, setKey] = reactExports.useState(0);
  let t2;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = () => {
      setKey(Math.random());
    };
    $[0] = t2;
  } else {
    t2 = $[0];
  }
  let t3;
  if ($[1] !== form) {
    t3 = [form];
    $[1] = form;
    $[2] = t3;
  } else {
    t3 = $[2];
  }
  reactExports.useEffect(t2, t3);
  let t4;
  if ($[3] !== fieldName || $[4] !== form) {
    t4 = (value) => {
      if (value) {
        const [year, month, day] = value.split("-").map(Number);
        const utcDate = new Date(Date.UTC(year, month - 1, day));
        const isoDate = utcDate.toISOString();
        form == null ? void 0 : form.setFieldValue(fieldName, isoDate);
      } else {
        form == null ? void 0 : form.setFieldValue(fieldName, null);
      }
    };
    $[3] = fieldName;
    $[4] = form;
    $[5] = t4;
  } else {
    t4 = $[5];
  }
  const handleDatePickerChange = t4;
  let t5;
  if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = {
      zIndex: 1400,
      withinPortal: false
    };
    $[6] = t5;
  } else {
    t5 = $[6];
  }
  let t6;
  if ($[7] !== className || $[8] !== classes.date || $[9] !== cx) {
    t6 = cx(classes.date, className);
    $[7] = className;
    $[8] = classes.date;
    $[9] = cx;
    $[10] = t6;
  } else {
    t6 = $[10];
  }
  const t7 = i18n.language;
  let t8;
  if ($[11] !== fieldName || $[12] !== form) {
    t8 = ((_b = (_a = form.getInputProps(fieldName)) == null ? void 0 : _a.value) == null ? void 0 : _b.length) && ((_d = (_c = form.getInputProps(fieldName)) == null ? void 0 : _c.value) == null ? void 0 : _d.length) !== null ? new Date(form.getInputProps(fieldName).value) : void 0;
    $[11] = fieldName;
    $[12] = form;
    $[13] = t8;
  } else {
    t8 = $[13];
  }
  let t9;
  if ($[14] !== fieldName || $[15] !== form) {
    t9 = form.getInputProps(fieldName);
    $[14] = fieldName;
    $[15] = form;
    $[16] = t9;
  } else {
    t9 = $[16];
  }
  let t10;
  if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
    t10 = /* @__PURE__ */ new Date();
    $[17] = t10;
  } else {
    t10 = $[17];
  }
  let t11;
  if ($[18] !== clearable || $[19] !== disabled || $[20] !== handleDatePickerChange || $[21] !== i18n.language || $[22] !== key || $[23] !== label || $[24] !== placeholder || $[25] !== t6 || $[26] !== t8 || $[27] !== t9.error || $[28] !== withAsterisk) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsx(DatePickerInput, { popoverProps: t5, "data-cy": "datePicker", className: t6, locale: t7, valueFormat: "DD.MM.YYYY", placeholder, label, disabled, clearable, defaultValue: t8, onChange: handleDatePickerChange, error: t9.error, maxDate: t10, withAsterisk }, key);
    $[18] = clearable;
    $[19] = disabled;
    $[20] = handleDatePickerChange;
    $[21] = i18n.language;
    $[22] = key;
    $[23] = label;
    $[24] = placeholder;
    $[25] = t6;
    $[26] = t8;
    $[27] = t9.error;
    $[28] = withAsterisk;
    $[29] = t11;
  } else {
    t11 = $[29];
  }
  return t11;
};
export {
  DatePicker as D
};
//# sourceMappingURL=index-DFZKJmic.js.map
