import { aj as requireInteropRequireDefault, ak as requireCreateSvgIcon, al as requireJsxRuntime, am as getDefaultExportFromCjs, u as useAtomValue, j as jsxRuntimeExports, an as CheckOutlinedIcon, ao as cn, t as React, k as Checkbox, z as currentTheme, G as Grid, I as IconButton, i as FormControlLabel, ai as Editor, B as Button, ab as formEdit } from "./index-D15x63tD.js";
var Square = {};
var hasRequiredSquare;
function requireSquare() {
  if (hasRequiredSquare) return Square;
  hasRequiredSquare = 1;
  var _interopRequireDefault = requireInteropRequireDefault();
  Object.defineProperty(Square, "__esModule", {
    value: true
  });
  Square.default = void 0;
  var _createSvgIcon = _interopRequireDefault(/* @__PURE__ */ requireCreateSvgIcon());
  var _jsxRuntime = requireJsxRuntime();
  Square.default = (0, _createSvgIcon.default)(/* @__PURE__ */ (0, _jsxRuntime.jsx)("path", {
    d: "M3 3h18v18H3z"
  }), "Square");
  return Square;
}
var SquareExports = /* @__PURE__ */ requireSquare();
const SquareIcon = /* @__PURE__ */ getDefaultExportFromCjs(SquareExports);
function CheckBoxPeriod(props) {
  const theme = useAtomValue(currentTheme);
  const Unchecked = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
  const Checked = /* @__PURE__ */ jsxRuntimeExports.jsx(CheckOutlinedIcon, { className: cn("fontColorStimate", { light: theme === "light" }) });
  const Required = /* @__PURE__ */ jsxRuntimeExports.jsx(SquareIcon, {});
  function getIcon(checkstate) {
    const icons = {
      0: Unchecked,
      1: Checked,
      2: Required
    };
    return icons[checkstate];
  }
  function getNextState(arr, state) {
    if (state === 2) return arr[1];
    const length = arr.length;
    const index = arr.indexOf(state);
    return index < length - 1 ? arr[index + 1] : arr[0];
  }
  const [icon, setIcon] = React.useState(Unchecked);
  const [checked, setChecked] = React.useState(false);
  const [stateCheckBox, setStateCheckBox] = React.useState();
  const checkStates = React.useRef();
  React.useEffect(() => {
    setChecked(false);
    checkStates.current = [0, 1];
    setStateCheckBox(props.CheckState ? Number(props.CheckState) : 0);
    if (props.checkRef) props.checkRef.current = setStateCheckBox;
  }, []);
  React.useEffect(() => {
    if (stateCheckBox !== void 0) {
      setIcon(getIcon(stateCheckBox));
    }
  }, [stateCheckBox]);
  React.useEffect(() => {
    setStateCheckBox(props.CheckState ? Number(props.CheckState) : 0);
  }, [props.CheckState]);
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    Checkbox,
    {
      icon,
      checkedIcon: icon,
      checked,
      onChange: (ev) => {
        let state = getNextState(checkStates.current, stateCheckBox);
        setStateCheckBox(state);
        if (props.onChange) {
          props.onChange({
            ev,
            setCheck: setStateCheckBox,
            checked: state === 1 ? true : false
          });
        }
      },
      sx: {
        "& .MuiSvgIcon-root": { fontSize: 18 }
      },
      style: {
        width: "15px",
        height: "15px",
        marginRight: "5px",
        marginLeft: "5px",
        borderRadius: "4px",
        border: "2px solid #aaaaaa",
        backgroundColor: "#f4f4f4"
      },
      type: "checkbox"
    }
  );
}
function DialogPeriodCurrentYear({ props }) {
  const [buttonMap, setButtonMap] = React.useState();
  const [currentYear, setCurrentYear] = React.useState();
  const firstCheck = React.useRef();
  const secondCheck = React.useRef();
  const thirdCheck = React.useRef();
  const fourthCheck = React.useRef();
  const firstState = React.useRef(getMonths(props.ObjRef));
  const checkboxMap = () => {
    return {
      1: firstCheck,
      2: firstCheck,
      3: firstCheck,
      4: secondCheck,
      5: secondCheck,
      6: secondCheck,
      7: thirdCheck,
      8: thirdCheck,
      9: thirdCheck,
      10: fourthCheck,
      11: fourthCheck,
      12: fourthCheck
    };
  };
  const symbolMap = () => {
    return {
      1: "Ⅰ",
      2: "Ⅱ",
      3: "Ⅲ",
      4: "Ⅳ",
      5: "Ⅴ",
      6: "Ⅵ",
      7: "Ⅶ",
      8: "Ⅷ",
      9: "Ⅸ",
      10: "Ⅹ",
      11: "Ⅺ",
      12: "Ⅻ"
    };
  };
  const checkstateMap = () => {
    return {
      1: [1, 2, 3],
      2: [1, 2, 3],
      3: [1, 2, 3],
      4: [4, 5, 6],
      5: [4, 5, 6],
      6: [4, 5, 6],
      7: [7, 8, 9],
      8: [7, 8, 9],
      9: [7, 8, 9],
      10: [10, 11, 12],
      11: [10, 11, 12],
      12: [10, 11, 12]
    };
  };
  const getCheckStateMap = () => {
    return {
      1: [1, 2, 3],
      2: [4, 5, 6],
      3: [7, 8, 9],
      4: [10, 11, 12]
    };
  };
  React.useEffect(() => {
    setButtonMap(firstState.current);
  }, []);
  React.useEffect(() => {
    if (buttonMap) {
      setCurrentYear(buttonMap.currentYear);
    }
  }, [buttonMap]);
  function getMonths(objref) {
    if (buttonMap !== void 0) return;
    const result = {};
    let checkBoxes = objref & 4095;
    for (let i = 0; i < 12; i++) {
      if (checkBoxes >> i & 1) {
        result[i + 1] = true;
      } else {
        result[i + 1] = false;
      }
    }
    result.year = objref >> 15;
    result.currentYear = objref > 4095 ? false : true;
    return result;
  }
  function buttonClick(ev) {
    const checkbox = checkboxMap()[ev.target.dataset.number];
    if (ev.target.dataset.pressed === "true") {
      buttonMap[ev.target.dataset.number] = false;
    } else {
      buttonMap[ev.target.dataset.number] = true;
    }
    ev.target.dataset.pressed = ev.target.dataset.pressed === "false" ? "true" : "false";
    checkbox.current(checkboxCheck(ev.target.dataset.number));
    setButtonMap({ ...buttonMap });
  }
  function checkboxCheck(index) {
    const states = checkstateMap()[index];
    if (buttonMap[states[0]] && buttonMap[states[1]] && buttonMap[states[2]]) {
      return 1;
    } else if (buttonMap[states[0]] || buttonMap[states[1]] || buttonMap[states[2]]) {
      return 2;
    } else {
      return 0;
    }
  }
  function getFirstCheckboxState(index) {
    let buttonMap2 = firstState.current;
    const states = getCheckStateMap()[index];
    if (buttonMap2[states[0]] && buttonMap2[states[1]] && buttonMap2[states[2]]) {
      return 1;
    } else if (buttonMap2[states[0]] || buttonMap2[states[1]] || buttonMap2[states[2]]) {
      return 2;
    } else {
      return 0;
    }
  }
  function onYearEdit(data) {
    buttonMap.year = data.value > 3e3 ? 3e3 : data.value;
    setButtonMap({ ...buttonMap });
  }
  function getTag(data) {
    let result = 0;
    for (let i = 12; i > 0; i--) {
      result += (data[i] ? 1 : 0) << i - 1;
    }
    if (data.currentYear) return result;
    return data.year << 15 | result;
  }
  async function onSelect() {
    if (props.onEdit) {
      props.onEdit({
        tag: getTag(buttonMap),
        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(buttonMap)
        },
        props.RequestID,
        props.from
      );
    }
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      Grid,
      {
        container: true,
        direction: "column",
        justifyContent: "flex-start",
        alignItems: "flex-start",
        style: { height: "calc(100% - 50px)" },
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Grid,
            {
              item: true,
              style: {
                height: "60px",
                width: "441px",
                border: "1px solid #cccccc",
                paddingTop: "11px",
                paddingLeft: "4.4px",
                borderRadius: "5px"
              },
              children: /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { container: true, direction: "row", justifyContent: "flex-start", alignItems: "flex-start", children: buttonMap ? Object.values(buttonMap).map((item, index) => {
                if (index > 11) return null;
                return /* @__PURE__ */ jsxRuntimeExports.jsx(
                  IconButton,
                  {
                    "data-pressed": item,
                    "data-number": index + 1,
                    style: {
                      width: "34px",
                      height: "34px",
                      borderRadius: "10%",
                      border: "1px solid #cccccc",
                      marginRight: "2px",
                      backgroundColor: item ? "#efefef" : "",
                      fontSize: "130%"
                    },
                    onClick: buttonClick,
                    children: symbolMap()[index + 1]
                  },
                  `month-bttn_${index}`
                );
              }) : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {}) })
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { item: true, children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(
              "div",
              {
                style: {
                  position: "absolute",
                  top: "124px",
                  left: "40px",
                  background: "white",
                  color: "#aaaaaa"
                },
                children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Год" })
              }
            ),
            /* @__PURE__ */ jsxRuntimeExports.jsx(
              "div",
              {
                style: {
                  position: "absolute",
                  top: "124px",
                  left: "185px",
                  background: "white",
                  color: "#aaaaaa"
                },
                children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Квартал" })
              }
            ),
            /* @__PURE__ */ jsxRuntimeExports.jsx(
              "div",
              {
                style: {
                  position: "absolute",
                  top: "48px",
                  left: "40px",
                  background: "white",
                  color: "#aaaaaa"
                },
                children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Периоды текущего года" })
              }
            ),
            /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { container: true, direction: "row", justifyContent: "flex-start", alignItems: "flex-start", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                Grid,
                {
                  item: true,
                  style: {
                    width: "140px",
                    height: "80px",
                    border: "1px solid #cccccc",
                    borderRadius: "5px",
                    marginTop: "15px",
                    marginRight: "5px"
                  },
                  children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { container: true, direction: "column", justifyContent: "flex-start", alignItems: "flex-start", children: [
                    /* @__PURE__ */ jsxRuntimeExports.jsx(
                      "div",
                      {
                        style: {
                          paddingLeft: "15px",
                          marginTop: "10px",
                          display: "flex",
                          alignItems: "center"
                        },
                        children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                          FormControlLabel,
                          {
                            control: /* @__PURE__ */ jsxRuntimeExports.jsx(
                              CheckBoxPeriod,
                              {
                                CheckState: buttonMap ? buttonMap.currentYear ? 1 : 0 : 0,
                                onChange: (data) => {
                                  setCurrentYear(!currentYear);
                                  buttonMap.currentYear = !buttonMap.currentYear;
                                  setButtonMap({ ...buttonMap });
                                }
                              }
                            ),
                            label: /* @__PURE__ */ jsxRuntimeExports.jsx("label", { style: { fontSize: "90%" }, children: "Текущий" })
                          }
                        )
                      }
                    ),
                    /* @__PURE__ */ jsxRuntimeExports.jsx(
                      "div",
                      {
                        style: {
                          border: "1px solid #eeeeee",
                          width: "80%",
                          marginLeft: "10px",
                          marginTop: "10px"
                        },
                        children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: currentYear ? /* @__PURE__ */ jsxRuntimeExports.jsx(
                          "div",
                          {
                            style: {
                              paddingLeft: "3px",
                              paddingTop: "2px",
                              height: "21px",
                              fontSize: "13px",
                              letterSpacing: "0px"
                            },
                            children: (/* @__PURE__ */ new Date()).getFullYear()
                          }
                        ) : /* @__PURE__ */ jsxRuntimeExports.jsx(
                          Editor,
                          {
                            value: `${buttonMap && buttonMap.year ? buttonMap.year : (/* @__PURE__ */ new Date()).getFullYear()}`,
                            onEdit: onYearEdit,
                            editStyle: "8"
                          }
                        ) })
                      }
                    )
                  ] })
                }
              ),
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                Grid,
                {
                  item: true,
                  style: {
                    width: "297px",
                    height: "80px",
                    border: "1px solid #cccccc",
                    borderRadius: "5px",
                    marginTop: "15px"
                  },
                  children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { container: true, direction: "row", justifyContent: "flex-start", alignItems: "flex-start", children: [
                    /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { item: true, style: { width: "50%" }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { container: true, direction: "column", justifyContent: "flex-start", alignItems: "flex-start", children: [
                      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { marginTop: "10px", paddingLeft: "15px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                        FormControlLabel,
                        {
                          sx: {
                            userSelect: "none"
                          },
                          control: /* @__PURE__ */ jsxRuntimeExports.jsx(
                            CheckBoxPeriod,
                            {
                              checkId: 1,
                              CheckState: getFirstCheckboxState(1),
                              checkRef: firstCheck,
                              onChange: (data) => {
                                buttonMap[1] = data.checked;
                                buttonMap[2] = data.checked;
                                buttonMap[3] = data.checked;
                                setButtonMap({ ...buttonMap });
                              }
                            }
                          ),
                          label: "1-й квартал"
                        }
                      ) }),
                      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { marginTop: "10px", paddingLeft: "15px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                        FormControlLabel,
                        {
                          sx: {
                            userSelect: "none"
                          },
                          control: /* @__PURE__ */ jsxRuntimeExports.jsx(
                            CheckBoxPeriod,
                            {
                              checkId: 2,
                              CheckState: getFirstCheckboxState(2),
                              checkRef: secondCheck,
                              onChange: (data) => {
                                buttonMap[4] = data.checked;
                                buttonMap[5] = data.checked;
                                buttonMap[6] = data.checked;
                                setButtonMap({ ...buttonMap });
                              }
                            }
                          ),
                          label: "2-й квартал"
                        }
                      ) })
                    ] }) }),
                    /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { item: true, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { container: true, direction: "column", justifyContent: "flex-start", alignItems: "flex-start", children: [
                      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { marginTop: "10px", marginLeft: "15px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                        FormControlLabel,
                        {
                          sx: {
                            userSelect: "none"
                          },
                          control: /* @__PURE__ */ jsxRuntimeExports.jsx(
                            CheckBoxPeriod,
                            {
                              checkId: 3,
                              CheckState: getFirstCheckboxState(3),
                              checkRef: thirdCheck,
                              onChange: (data) => {
                                buttonMap[7] = data.checked;
                                buttonMap[8] = data.checked;
                                buttonMap[9] = data.checked;
                                setButtonMap({ ...buttonMap });
                              }
                            }
                          ),
                          label: "3-й квартал"
                        }
                      ) }),
                      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { marginTop: "10px", marginLeft: "15px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                        FormControlLabel,
                        {
                          sx: {
                            userSelect: "none"
                          },
                          control: /* @__PURE__ */ jsxRuntimeExports.jsx(
                            CheckBoxPeriod,
                            {
                              checkId: 4,
                              CheckState: getFirstCheckboxState(4),
                              checkRef: fourthCheck,
                              onChange: (data) => {
                                buttonMap[10] = data.checked;
                                buttonMap[11] = data.checked;
                                buttonMap[12] = data.checked;
                                setButtonMap({ ...buttonMap });
                              }
                            }
                          ),
                          label: "4-й квартал"
                        }
                      ) })
                    ] }) })
                  ] })
                }
              )
            ] })
          ] })
        ]
      }
    ),
    /* @__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 {
  DialogPeriodCurrentYear as default
};
//# sourceMappingURL=DialogPeriodCurrentYear-C0Shcw0n.js.map
