import { E as compilerRuntimeExports, r as reactExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { T as TextFieldInput } from "./index-BvQfhnV_.js";
import { c as createStyles, W as useMediaQuery, a0 as SimpleGrid, b as Box, O as Badge, h as ActionIcon } from "./vendor-mantine-h0WlM2Mj.js";
import { w as qXe, C as ES } from "./vendor-icons-xWhXK_Ui.js";
import { O as themeColors } from "./index-DfebxkL9.js";
import { A as AddButton } from "./index-72JBTuLT.js";
import { S as SelectUserModal } from "./index-DFEP7Sv_.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { a as arrayType, o as objectType, s as stringType, l as literalType, n as numberType } from "./types-espwwxTQ.js";
const useStyles = createStyles((theme, _, utils) => ({
  addBtn: {
    flex: 1,
    borderRadius: "8px",
    border: `1px solid ${theme.colors.brandGray[0]}`,
    marginBottom: "auto",
    "& .mantine-UnstyledButton-root .mantine-Button-root": {
      marginTop: 0
    },
    "&:hover": {
      backgroundColor: "#f6f7f8"
    },
    "& .mantine-Button-inner": {
      display: "flex",
      flexDirection: "row",
      alignItems: "center",
      justifyContent: "space-between"
    },
    "& .mantine-Button-label": {
      color: theme.black
    }
  },
  badge: {
    alignItems: "center",
    justifyContent: "space-between",
    display: "flex",
    flex: 1,
    paddingRight: 3,
    backgroundColor: theme.colors.backgroundGray[6],
    color: "black",
    borderRadius: "16px",
    border: "none",
    textTransform: "inherit",
    fontSize: "14px",
    fontWeight: 400,
    height: "2.25rem"
  },
  removeButton: {
    marginBottom: "2px",
    marginTop: "auto",
    display: "flex",
    alignItems: "flex-end",
    "& .mantine-ActionIcon-root": {
      display: "flex",
      alignItems: "center",
      alignSelf: "center",
      [utils.smallerThan("xs")]: {
        alignItems: "flex-start",
        position: "absolute",
        top: "50%",
        right: "0",
        transform: "translate(100%, -50%)"
      }
    },
    "& button:hover": {
      backgroundColor: "transparent"
    }
  },
  addManagerContainer: {
    display: "flex",
    alignItems: "center",
    width: "100%",
    gridTemplateColumns: "1fr 50px",
    marginBottom: "auto"
  }
}));
const Positions = (t0) => {
  const $ = compilerRuntimeExports.c(34);
  const {
    form,
    sectionFormKey,
    Positions: Positions2,
    isLimitedAccess,
    disabled
  } = t0;
  const {
    t
  } = useTranslation();
  const {
    classes,
    theme
  } = useStyles();
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = {};
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const selectedUser = t1;
  const [selectOwnerModal, setSelectOwnerModal] = reactExports.useState(false);
  const [selectedPositionId, setSelectPositionId] = reactExports.useState(null);
  const isMobile = useMediaQuery("(max-width: 576px)");
  let t2;
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = () => {
      setSelectOwnerModal(false);
      setSelectPositionId(null);
    };
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  const closeSelectOwnerModal = t2;
  let t3;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t3 = (index) => {
      setSelectPositionId(index);
      setSelectOwnerModal(true);
    };
    $[2] = t3;
  } else {
    t3 = $[2];
  }
  const openSelectOwnerModal = t3;
  let t4;
  if ($[3] !== form || $[4] !== sectionFormKey || $[5] !== selectedPositionId) {
    t4 = (parent) => {
      if (selectedPositionId !== null && form) {
        form == null ? void 0 : form.setFieldValue(`${sectionFormKey}.${selectedPositionId}.Director`, {
          Id: parent.Id,
          Name: parent.Name
        });
      }
      closeSelectOwnerModal();
    };
    $[3] = form;
    $[4] = sectionFormKey;
    $[5] = selectedPositionId;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  const handleChangePositionParent = t4;
  let t5;
  if ($[7] !== Positions2 || $[8] !== classes || $[9] !== disabled || $[10] !== form || $[11] !== isLimitedAccess || $[12] !== isMobile || $[13] !== sectionFormKey || $[14] !== t || $[15] !== theme) {
    t5 = (Positions2 == null ? void 0 : Positions2.length) ? Positions2 == null ? void 0 : Positions2.map((position, index_0) => /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { w: "100%", cols: {
      base: 1,
      xs: 2
    }, mt: isMobile ? theme.spacing.sm : 0, verticalSpacing: "sm", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextFieldInput, { disabled: disabled || isLimitedAccess, fieldName: `${sectionFormKey}.${index_0}.Position.Name`, label: t("profile.position"), form, withAsterisk: true, dataAttribute: `${sectionFormKey}.${index_0}.Position.Name` }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.addManagerContainer, mt: !isMobile ? "24px" : 0, children: [
        position.Director ? /* @__PURE__ */ jsxRuntimeExports.jsx(Badge, { className: classes.badge, variant: "outline", "data-cy": `${position.Director.Name}`, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isLimitedAccess ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { size: 24, variant: "transparent", onClick: async () => {
          const prevErrors = form.errors;
          await form.setFieldValue(`${sectionFormKey}.${index_0}`, {
            Position: position.Position,
            Director: null
          });
          await form.setErrors(prevErrors);
        }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(qXe, { size: 16, color: themeColors.brandGray[0] }) }) }), children: position.Director.Name }) : isLimitedAccess ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { className: classes.addBtn, onClick: () => openSelectOwnerModal(index_0), "data-cy": "addManagerBtn", disabled, children: t("profile.addManager") }),
        isLimitedAccess ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { ml: 10, size: 30, onClick: () => form.removeListItem(`${sectionFormKey}`, index_0), children: /* @__PURE__ */ jsxRuntimeExports.jsx(ES, { color: "#667085" }) })
      ] })
    ] }, index_0)) : isLimitedAccess ? /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: t("profile.noPosition") }) : null;
    $[7] = Positions2;
    $[8] = classes;
    $[9] = disabled;
    $[10] = form;
    $[11] = isLimitedAccess;
    $[12] = isMobile;
    $[13] = sectionFormKey;
    $[14] = t;
    $[15] = theme;
    $[16] = t5;
  } else {
    t5 = $[16];
  }
  let t6;
  if ($[17] !== classes || $[18] !== disabled || $[19] !== form || $[20] !== isLimitedAccess || $[21] !== sectionFormKey || $[22] !== t) {
    t6 = isLimitedAccess ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(SimpleGrid, { cols: {
      base: 1,
      xs: 2
    }, mt: 16, w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { className: classes.addBtn, onClick: () => form == null ? void 0 : form.insertListItem(`${sectionFormKey}`, {
      Position: {
        Name: ""
      },
      Director: ""
    }), "data-cy": "addPositionBtn", disabled, children: t("profile.addPosition") }) });
    $[17] = classes;
    $[18] = disabled;
    $[19] = form;
    $[20] = isLimitedAccess;
    $[21] = sectionFormKey;
    $[22] = t;
    $[23] = t6;
  } else {
    t6 = $[23];
  }
  let t7;
  if ($[24] !== t) {
    t7 = t("profile.addManager");
    $[24] = t;
    $[25] = t7;
  } else {
    t7 = $[25];
  }
  let t8;
  if ($[26] !== handleChangePositionParent || $[27] !== selectOwnerModal || $[28] !== t7) {
    t8 = /* @__PURE__ */ jsxRuntimeExports.jsx(SelectUserModal, { multipleUsers: false, isOpened: selectOwnerModal, title: t7, onClose: closeSelectOwnerModal, setSelectedUsers: handleChangePositionParent, userId: selectedUser.Id });
    $[26] = handleChangePositionParent;
    $[27] = selectOwnerModal;
    $[28] = t7;
    $[29] = t8;
  } else {
    t8 = $[29];
  }
  let t9;
  if ($[30] !== t5 || $[31] !== t6 || $[32] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t5,
      t6,
      t8
    ] });
    $[30] = t5;
    $[31] = t6;
    $[32] = t8;
    $[33] = t9;
  } else {
    t9 = $[33];
  }
  return t9;
};
const defaultError = (field) => `Введите ${field}`;
arrayType(objectType({
  Position: stringType().min(1, {
    message: defaultError("должность")
  }).optional().or(literalType("")),
  ParentUserId: numberType({
    invalid_type_error: defaultError("руководитель")
  }).positive({
    message: defaultError("отдел")
  }).optional().or(literalType(0)),
  ParentUserName: stringType().min(1, {
    message: defaultError("должность")
  }).optional().or(literalType(""))
}));
export {
  Positions as P
};
//# sourceMappingURL=index-CUcivY9l.js.map
