import { t as React, j as jsxRuntimeExports, G as Grid, ai as Editor, B as Button, ab as formEdit } from "./index-D15x63tD.js";
function DialogPeriodTime({ props }) {
  const [year, setYear] = React.useState("0");
  const [month, setMonth] = React.useState("0");
  const [day, setDay] = React.useState("0");
  function getData(objref) {
    const d = `${objref >> 16}`;
    const m = `${objref >> 8 & 255}`;
    const y = `${objref & 255}`;
    return { year: y, month: m, day: d };
  }
  React.useEffect(() => {
    const data = getData(props.ObjRef);
    setYear(data.year);
    setMonth(data.month);
    setDay(data.day);
  }, []);
  function yearEdit(data) {
    if (data.value < 0) {
      setYear("0");
      data.setInputValue("0");
      return;
    }
    if (data.value > 251) {
      setYear("251");
      data.setInputValue("251");
      return;
    }
    setYear(data.value);
  }
  function monthEdit(data) {
    if (data.value < 0) {
      setMonth("0");
      data.setInputValue("0");
      return;
    }
    if (data.value > 251) {
      setMonth("251");
      data.setInputValue("251");
      return;
    }
    setMonth(data.value);
  }
  function dayEdit(data) {
    if (data.value < 0) {
      setDay("0");
      data.setInputValue("0");
      return;
    }
    if (data.value > 251) {
      setDay("251");
      data.setInputValue("251");
      return;
    }
    setDay(data.value);
  }
  function getTag() {
    return day << 16 | month << 8 | year;
  }
  async function onSelect() {
    if (props.onEdit) {
      props.onEdit({
        tag: getTag(),
        name: props.Name,
        record: props.record,
        textchanged: "0",
        setValue: props.setValue,
        setInputValue: props.setInputValue,
        type: props.Module,
        requestId: props.RequestID,
        addInfo: props.addInfo
      });
    }
    if (props.RequestID) {
      await formEdit(
        "1",
        props.func,
        {
          Name: "ObjRef",
          Value: getTag()
        },
        props.RequestID,
        props.from
      );
    }
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      Grid,
      {
        container: true,
        direction: "row",
        justifyContent: "flex-start",
        alignItems: "flex-start",
        style: {
          marginBottom: "15px"
        },
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { item: true, style: { width: "60px" }, children: "Годы:" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Grid,
            {
              item: true,
              style: {
                width: "170px",
                height: "27px",
                border: "1px solid #eeeeee"
              },
              children: /* @__PURE__ */ jsxRuntimeExports.jsx(Editor, { value: year, editStyle: "8", onEdit: yearEdit })
            }
          )
        ]
      }
    ),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      Grid,
      {
        container: true,
        direction: "row",
        justifyContent: "flex-start",
        alignItems: "flex-start",
        style: {
          marginBottom: "15px"
        },
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { item: true, style: { width: "60px" }, children: "Месяцы:" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Grid,
            {
              item: true,
              style: {
                width: "170px",
                height: "27px",
                border: "1px solid #eeeeee"
              },
              children: /* @__PURE__ */ jsxRuntimeExports.jsx(Editor, { value: month, editStyle: "8", onEdit: monthEdit })
            }
          )
        ]
      }
    ),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { container: true, direction: "row", justifyContent: "flex-start", alignItems: "flex-start", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { item: true, style: { width: "60px" }, children: "Дни:" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Grid,
        {
          item: true,
          style: {
            width: "170px",
            height: "27px",
            border: "1px solid #eeeeee"
          },
          children: /* @__PURE__ */ jsxRuntimeExports.jsx(Editor, { value: day, editStyle: "8", onEdit: dayEdit })
        }
      )
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(
      Grid,
      {
        item: true,
        style: {
          width: "100%",
          height: "40px",
          marginTop: "5px"
        },
        children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { container: true, direction: "row", justifyContent: "flex-end", alignItems: "center", style: { paddingTop: "8px" }, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button,
            {
              size: "small",
              variant: "outlined",
              style: { textTransform: "none", marginRight: "10px" },
              value: "1",
              className: "button_Modal_Select",
              onClick: onSelect,
              children: "Выбрать"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button,
            {
              size: "small",
              variant: "outlined",
              style: { textTransform: "none" },
              value: "2",
              className: "button_Modal_Close",
              children: "Отмена"
            }
          )
        ] })
      }
    )
  ] });
}
export {
  DialogPeriodTime as default
};
//# sourceMappingURL=DialogPeriodTime-BTfU_-WT.js.map
