import { r as reactExports, j as jsxRuntimeExports, E as compilerRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { s as storageConfigurationApiArea } from "./index-BVQ-Y7LP.js";
import { P as PopUpUI } from "./index-DGrXxZ89.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { B as Button, g as Loader, a4 as Select, s as showNotification, S as Stack, ag as Alert, a1 as Progress, T as Text, F as Flex, E as TextInput, d as Checkbox, k as Tooltip, $ as Table, af as Switch, h as ActionIcon, V as LoadingOverlay, W as useMediaQuery } from "./vendor-mantine-h0WlM2Mj.js";
import { J as IconChevronDown, aj as IconAlertCircle, F as IconX, ak as IconDotsVertical, A as IconEdit, al as IconBrandCitymapper, y as IconTrash, am as sZ } from "./vendor-icons-xWhXK_Ui.js";
import { A as AddButton } from "./index-72JBTuLT.js";
import "./index-DfebxkL9.js";
var StorageType = /* @__PURE__ */ ((StorageType2) => {
  StorageType2[StorageType2["Unknown"] = 0] = "Unknown";
  StorageType2[StorageType2["S3"] = 1] = "S3";
  StorageType2[StorageType2["Fs"] = 2] = "Fs";
  StorageType2[StorageType2["Encrypted"] = 4] = "Encrypted";
  StorageType2[StorageType2["S3Encrypted"] = 5] = "S3Encrypted";
  StorageType2[StorageType2["FsEncrypted"] = 6] = "FsEncrypted";
  return StorageType2;
})(StorageType || {});
var UserTaskStatus = /* @__PURE__ */ ((UserTaskStatus2) => {
  UserTaskStatus2[UserTaskStatus2["Canceled"] = -2] = "Canceled";
  UserTaskStatus2[UserTaskStatus2["Error"] = -1] = "Error";
  UserTaskStatus2[UserTaskStatus2["Unknown"] = 0] = "Unknown";
  UserTaskStatus2[UserTaskStatus2["Register"] = 1] = "Register";
  UserTaskStatus2[UserTaskStatus2["Start"] = 2] = "Start";
  UserTaskStatus2[UserTaskStatus2["Done"] = 3] = "Done";
  UserTaskStatus2[UserTaskStatus2["DoneWithErrors"] = 4] = "DoneWithErrors";
  return UserTaskStatus2;
})(UserTaskStatus || {});
const loadingContainer = "_loadingContainer_208p7_1";
const container = "_container_208p7_9";
const processDialog = "_processDialog_208p7_20";
const title = "_title_208p7_35";
const form = "_form_208p7_67";
const actionsWrapper = "_actionsWrapper_208p7_77";
const actions = "_actions_208p7_77";
const removeDialog = "_removeDialog_208p7_105";
const removeDialogQuestion = "_removeDialogQuestion_208p7_114";
const removeDialogActions = "_removeDialogActions_208p7_120";
const transferDialog = "_transferDialog_208p7_128";
const transferDialogQuestion = "_transferDialogQuestion_208p7_137";
const transferDialogActions = "_transferDialogActions_208p7_143";
const classes$2 = {
  loadingContainer,
  container,
  processDialog,
  title,
  form,
  actionsWrapper,
  actions,
  removeDialog,
  removeDialogQuestion,
  removeDialogActions,
  transferDialog,
  transferDialogQuestion,
  transferDialogActions
};
const useStoragePage = () => {
  const [storages, setStorages] = reactExports.useState([]);
  const [isLoading, setLoading] = reactExports.useState(true);
  const fetchStorages = reactExports.useCallback(async () => {
    try {
      setLoading(true);
      const data = await storageConfigurationApiArea().GetStorageConfigurations();
      setStorages(data);
    } catch (error) {
    } finally {
      setLoading(false);
    }
  }, []);
  reactExports.useEffect(() => {
    fetchStorages();
  }, [fetchStorages]);
  return {
    storages,
    isLoading,
    fetchStorages
  };
};
const headerCell = "_headerCell_u8tiy_1";
const classes$1 = {
  headerCell
};
const tableCell = "_tableCell_1ggpy_1";
const progressWrapper = "_progressWrapper_1ggpy_9";
const classes = {
  tableCell,
  progressWrapper
};
const DeleteDialog = (props) => {
  const {
    t
  } = useTranslation();
  const {
    handleClosePopUp,
    storageId,
    onSuccess
  } = props;
  const [isLoading, setIsLoading] = reactExports.useState(false);
  const handleDelete = async () => {
    try {
      setIsLoading(true);
      await storageConfigurationApiArea().DeleteStorageConfiguration({
        id: storageId
      });
      if (onSuccess) {
        await onSuccess();
      }
      handleClosePopUp();
    } catch (error) {
    } finally {
      setIsLoading(false);
    }
  };
  const handleCancel = () => {
    handleClosePopUp();
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.removeDialog, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.removeDialogQuestion, children: t("storagePage.deleteDialog.confirmMessage") }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.removeDialogActions, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "gray", variant: "light", onClick: handleCancel, disabled: isLoading, children: t("storagePage.deleteDialog.cancelButton") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "red", variant: "light", onClick: handleDelete, loading: isLoading, disabled: isLoading, children: t("storagePage.deleteDialog.deleteButton") })
    ] })
  ] });
};
const TransferDialog = (props) => {
  const {
    t
  } = useTranslation();
  const {
    handleClosePopUp,
    fromStorageId,
    onMigrationStarted
  } = props;
  const [isLoading, setIsLoading] = reactExports.useState(false);
  const [isFetching, setIsFetching] = reactExports.useState(true);
  const [storages, setStorages] = reactExports.useState([]);
  const [selectedStorage, setSelectedStorage] = reactExports.useState(null);
  reactExports.useEffect(() => {
    const fetchStorages = async () => {
      try {
        setIsFetching(true);
        const data = await storageConfigurationApiArea().GetStorageConfigurations();
        const availableStorages = data.filter((storage) => storage.Id !== fromStorageId && storage.IsEnabled);
        setStorages(availableStorages);
      } catch (error) {
      } finally {
        setIsFetching(false);
      }
    };
    fetchStorages();
  }, [fromStorageId]);
  const handleTransfer = async () => {
    if (!selectedStorage) return;
    try {
      setIsLoading(true);
      const migrationData = await storageConfigurationApiArea().MigrateStorage({
        from: fromStorageId,
        to: Number(selectedStorage)
      });
      showNotification({
        title: t("storagePage.notifications.migrationStarted"),
        message: "",
        autoClose: true,
        color: "green",
        style: {
          zIndex: 1003
        }
      });
      if (onMigrationStarted) {
        onMigrationStarted(migrationData.TaskId, Number(selectedStorage));
      }
      handleClosePopUp();
    } catch (error_0) {
      showNotification({
        title: t("storagePage.errors.migratingStorage"),
        message: "",
        autoClose: true,
        color: "red",
        style: {
          zIndex: 1003
        }
      });
    } finally {
      setIsLoading(false);
    }
  };
  const handleCancel = () => {
    handleClosePopUp();
  };
  const storageOptions = storages.map((storage_0) => ({
    value: storage_0.Id.toString(),
    label: storage_0.Name
  }));
  if (isFetching) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.transferDialog, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: {
      display: "flex",
      justifyContent: "center",
      padding: "20px"
    }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { color: "blue" }) }) });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.transferDialog, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.transferDialogQuestion, children: t("storagePage.transferDialog.title") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { value: selectedStorage, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconChevronDown, { size: "1rem", color: "#98A2B3" }), onChange: setSelectedStorage, className: classes$2.select, data: storageOptions, label: t("storagePage.transferDialog.targetLabel"), placeholder: t("storagePage.transferDialog.targetPlaceholder"), comboboxProps: {
      withinPortal: false,
      transitionProps: {
        transition: "pop",
        duration: 200
      },
      offset: -20
    }, disabled: storages.length === 0 }),
    storages.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: {
      color: "#666",
      fontSize: "14px",
      marginTop: "8px"
    }, children: t("storagePage.transferDialog.noStoragesAvailable") }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.transferDialogActions, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "gray", variant: "light", onClick: handleCancel, disabled: isLoading, children: t("storagePage.transferDialog.cancelButton") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "blue", variant: "light", onClick: handleTransfer, disabled: !selectedStorage || isLoading, loading: isLoading, children: t("storagePage.transferDialog.transferButton") })
    ] })
  ] });
};
const MigrationProgressDialog = (props) => {
  const {
    t
  } = useTranslation();
  const {
    storageId,
    fromStorageId,
    toStorageId,
    onSuccess,
    onCancel,
    onProgressUpdate,
    onRetry,
    handleClosePopUp
  } = props;
  const [migrationData, setMigrationData] = reactExports.useState(null);
  const [isCancelling, setIsCancelling] = reactExports.useState(false);
  const [isRetrying, setIsRetrying] = reactExports.useState(false);
  reactExports.useEffect(() => {
    const fetchMigrationStatus = async () => {
      try {
        const data = await storageConfigurationApiArea().GetMigrationStatus({
          id: storageId
        });
        setMigrationData(data);
        if (onProgressUpdate) {
          onProgressUpdate(data.Percent);
        }
        if (data.Status === UserTaskStatus.Done || data.Percent >= 100) {
          setTimeout(() => {
            if (onSuccess) {
              onSuccess();
            }
            handleClosePopUp();
          }, 1e3);
        }
      } catch (error) {
      }
    };
    const interval = setInterval(fetchMigrationStatus, 3e3);
    fetchMigrationStatus();
    return () => clearInterval(interval);
  }, [storageId, onSuccess, onProgressUpdate, handleClosePopUp]);
  const handleCancel = async () => {
    try {
      setIsCancelling(true);
      await storageConfigurationApiArea().CancelMigration({
        id: storageId
      });
      showNotification({
        title: t("storagePage.notifications.migrationCancelled"),
        message: "",
        autoClose: true,
        color: "blue",
        style: {
          zIndex: 1003
        }
      });
      if (onCancel) {
        await onCancel();
      }
      handleClosePopUp();
    } catch (error_0) {
      showNotification({
        title: t("storagePage.notifications.migrationCancelError"),
        message: "",
        autoClose: true,
        color: "red",
        style: {
          zIndex: 1003
        }
      });
    } finally {
      setIsCancelling(false);
    }
  };
  const percent = (migrationData == null ? void 0 : migrationData.Percent) || 0;
  const hasError = (migrationData == null ? void 0 : migrationData.Status) === UserTaskStatus.Error || (migrationData == null ? void 0 : migrationData.Status) === UserTaskStatus.Canceled || (migrationData == null ? void 0 : migrationData.Status) === UserTaskStatus.DoneWithErrors;
  const canRetry = fromStorageId && toStorageId && toStorageId !== 0;
  const handleRetry = async () => {
    try {
      setIsRetrying(true);
      if (!fromStorageId || !toStorageId || toStorageId === 0) {
        showNotification({
          title: t("storagePage.notifications.migrationRetryError"),
          message: t("storagePage.notifications.invalidStorageIds"),
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
        return;
      }
      const newMigrationData = await storageConfigurationApiArea().MigrateStorage({
        from: fromStorageId,
        to: toStorageId
      });
      showNotification({
        title: t("storagePage.notifications.migrationRetryStarted"),
        message: "",
        autoClose: true,
        color: "blue",
        style: {
          zIndex: 1003
        }
      });
      if (onRetry) {
        onRetry(newMigrationData.TaskId);
      }
      handleClosePopUp();
    } catch (error_1) {
      showNotification({
        title: t("storagePage.notifications.migrationRetryError"),
        message: "",
        autoClose: true,
        color: "red",
        style: {
          zIndex: 1003
        }
      });
    } finally {
      setIsRetrying(false);
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.processDialog, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.form, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Stack, { gap: "lg", children: hasError ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Alert, { icon: /* @__PURE__ */ jsxRuntimeExports.jsx(IconAlertCircle, { size: "1rem" }), color: "red", variant: "light", children: t("storagePage.migrationProgressError") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Progress, { value: 100, size: "md", radius: "xs", color: "red" })
    ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", c: "dimmed", children: t("storagePage.migrationProgress.description") }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { gap: "xs", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Progress, { value: percent, size: "md", radius: "xs" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { size: "sm", ta: "center", fw: 500, children: [
          Math.round(percent),
          "%"
        ] })
      ] })
    ] }) }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, onClick: handleCancel, variant: "light", disabled: isCancelling, loading: isCancelling, children: t("storagePage.migrationProgress.cancelButton") }),
    hasError && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.actions, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, onClick: handleClosePopUp, variant: "light", color: "gray", children: t("storagePage.migrationProgressCancel") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, onClick: handleRetry, variant: "light", disabled: isRetrying || !canRetry, loading: isRetrying, children: t("storagePage.migrationProgressRetry") })
    ] })
  ] });
};
const EditStorageDialog = (props) => {
  const {
    t
  } = useTranslation();
  const {
    itemToEditId,
    handleClosePopUp
  } = props;
  const [isLoading, setIsLoading] = reactExports.useState(false);
  const [isFetching, setIsFetching] = reactExports.useState(true);
  const [isValidating, setIsValidating] = reactExports.useState(false);
  const [isValidated, setIsValidated] = reactExports.useState(false);
  const [validationError, setValidationError] = reactExports.useState(null);
  const TypeOptions = [{
    label: t("storagePage.storageTypes.s3"),
    value: "S3"
  }, {
    label: t("storagePage.storageTypes.fileStorage"),
    value: "Fs"
  }];
  const [name, setName] = reactExports.useState("");
  const [baseType, setBaseType] = reactExports.useState("S3");
  const [isEncrypted, setIsEncrypted] = reactExports.useState(false);
  const [s3Key, setS3Key] = reactExports.useState("");
  const [s3Secret, setS3Secret] = reactExports.useState("");
  const [s3SystemName, setS3SystemName] = reactExports.useState("");
  const [s3Url, setS3Url] = reactExports.useState("");
  const [s3Bucket, setS3Bucket] = reactExports.useState("");
  const [fsUrl, setFsUrl] = reactExports.useState("");
  reactExports.useEffect(() => {
    const fetchStorage = async () => {
      try {
        setIsFetching(true);
        const data = await storageConfigurationApiArea().GetStorageConfigurationById(itemToEditId);
        setName(data.Name);
        if (data.Type === StorageType.S3 || data.Type === StorageType.S3Encrypted) {
          setBaseType("S3");
          setIsEncrypted(data.Type === StorageType.S3Encrypted);
        } else {
          setBaseType("Fs");
          setIsEncrypted(data.Type === StorageType.FsEncrypted);
        }
        if (data.S3ConfigurationSettings) {
          setS3Key(data.S3ConfigurationSettings.Key);
          setS3Secret(data.S3ConfigurationSettings.Secret);
          setS3SystemName(data.S3ConfigurationSettings.SystemName);
          setS3Bucket(data.S3ConfigurationSettings.Bucket);
          setS3Url(data.S3ConfigurationSettings.Url);
        }
        if (data.FsConfigurationSettings) {
          setFsUrl(data.FsConfigurationSettings.Host);
        }
      } catch (error) {
      } finally {
        setIsFetching(false);
      }
    };
    if (itemToEditId) {
      fetchStorage();
    }
  }, [itemToEditId]);
  const onChange = (value) => {
    if (value === "S3" || value === "Fs") {
      setBaseType(value);
      resetValidation();
    }
  };
  const resetValidation = () => {
    setIsValidated(false);
    setValidationError(null);
  };
  const getBaseStorageType = () => {
    return baseType === "S3" ? StorageType.S3 : StorageType.Fs;
  };
  const isS3Type = baseType === "S3";
  const isFsType = baseType === "Fs";
  const handleValidate = async () => {
    try {
      setIsValidating(true);
      setValidationError(null);
      const storageType = getBaseStorageType();
      let result;
      if (isS3Type) {
        result = await storageConfigurationApiArea().ValidateStorageConfiguration({
          Name: name,
          Type: storageType,
          S3ConfigurationSettings: {
            Key: s3Key,
            Secret: s3Secret,
            SystemName: s3SystemName,
            Bucket: s3Bucket,
            Url: s3Url
          },
          IsEncrypted: isEncrypted
        });
      } else if (isFsType) {
        result = await storageConfigurationApiArea().ValidateStorageConfiguration({
          Name: name,
          Type: storageType,
          FsConfigurationSettings: {
            Host: fsUrl
          },
          IsEncrypted: isEncrypted
        });
      } else {
        return false;
      }
      if (result.Success) {
        setIsValidated(true);
        setValidationError(null);
        return true;
      } else {
        setIsValidated(false);
        let errorMessage = "Validation failed";
        if (result.Details && result.Details.Errors.length > 0) {
          errorMessage = result.Details.Errors.join("; ");
        } else if (result.FailedValidation.length > 0) {
          errorMessage = `Validation failed for: ${result.FailedValidation.join(", ")}`;
        }
        setValidationError(errorMessage);
        return false;
      }
    } catch (error_0) {
      setIsValidated(false);
      setValidationError(error_0 instanceof Error ? error_0.message : "Unknown validation error");
      return false;
    } finally {
      setIsValidating(false);
    }
  };
  const handleSave = async () => {
    try {
      setIsLoading(true);
      if (!isValidated) {
        const validationResult = await handleValidate();
        if (!validationResult) {
          setIsLoading(false);
          return;
        }
      }
      const storageType_0 = getBaseStorageType();
      if (isS3Type) {
        await storageConfigurationApiArea().UpdateStorageConfiguration({
          id: itemToEditId,
          Name: name,
          Type: storageType_0,
          S3ConfigurationSettings: {
            Key: s3Key,
            Secret: s3Secret,
            SystemName: s3SystemName,
            Bucket: s3Bucket,
            Url: s3Url
          },
          IsEncrypted: isEncrypted
        });
      } else if (isFsType) {
        await storageConfigurationApiArea().UpdateStorageConfiguration({
          id: itemToEditId,
          Name: name,
          Type: storageType_0,
          FsConfigurationSettings: {
            Host: fsUrl
          },
          IsEncrypted: isEncrypted
        });
      }
      if (props.onSuccess) {
        await props.onSuccess();
      }
      handleClosePopUp();
    } catch (error_1) {
    } finally {
      setIsLoading(false);
    }
  };
  const handleCancel = () => {
    handleClosePopUp();
  };
  const isFormValid = () => {
    if (!name) return false;
    if (isS3Type) {
      return s3Key && s3Secret && s3SystemName && s3Bucket && s3Url;
    }
    if (isFsType) {
      return fsUrl;
    }
    return false;
  };
  const getValidateTooltip = () => {
    if (!isFormValid()) {
      return t("storagePage.editDialog.tooltips.fillRequiredFields");
    }
    return "";
  };
  const getSaveTooltip = () => {
    if (!isFormValid()) {
      return t("storagePage.editDialog.tooltips.fillRequiredFields");
    }
    if (!isValidated) {
      return t("storagePage.editDialog.tooltips.validateFirst");
    }
    return "";
  };
  if (isFetching) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.container, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: {
      display: "flex",
      justifyContent: "center",
      padding: "20px"
    }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { color: "blue" }) }) });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.container, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.form, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { gap: "md", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", gap: "md", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { style: {
          flex: 1
        }, value: baseType, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconChevronDown, { size: "1rem", color: "#98A2B3" }), onChange, data: TypeOptions, label: t("storagePage.createDialog.typeLabel"), placeholder: t("storagePage.createDialog.typePlaceholder"), comboboxProps: {
          transitionProps: {
            transition: "pop",
            duration: 200
          },
          offset: -20,
          withinPortal: false
        }, disabled: true }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { style: {
          flex: 1
        }, placeholder: t("storagePage.createDialog.namePlaceholder"), label: t("storagePage.createDialog.nameLabel"), withAsterisk: true, value: name, onChange: (e) => {
          setName(e.target.value);
          resetValidation();
        } })
      ] }),
      isS3Type && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3KeyPlaceholder"), label: t("storagePage.createDialog.s3KeyLabel"), withAsterisk: true, value: s3Key, onChange: (e_0) => {
          setS3Key(e_0.target.value);
          resetValidation();
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3SecretPlaceholder"), label: t("storagePage.createDialog.s3SecretLabel"), withAsterisk: true, type: "password", value: s3Secret, onChange: (e_1) => {
          setS3Secret(e_1.target.value);
          resetValidation();
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3SystemNamePlaceholder"), label: t("storagePage.createDialog.s3SystemNameLabel"), withAsterisk: true, value: s3SystemName, onChange: (e_2) => {
          setS3SystemName(e_2.target.value);
          resetValidation();
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3UrlPlaceholder"), label: t("storagePage.createDialog.s3UrlLabel"), withAsterisk: true, value: s3Url, onChange: (e_3) => {
          setS3Url(e_3.target.value);
          resetValidation();
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3BucketPlaceholder"), label: t("storagePage.createDialog.s3BucketLabel"), withAsterisk: true, value: s3Bucket, onChange: (e_4) => {
          setS3Bucket(e_4.target.value);
          resetValidation();
        } })
      ] }),
      isFsType && /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.fsUrlPlaceholder"), label: t("storagePage.createDialog.fsUrlLabel"), withAsterisk: true, value: fsUrl, onChange: (e_5) => {
        setFsUrl(e_5.target.value);
        resetValidation();
      } }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { label: t("storagePage.createDialog.enableEncryption"), checked: isEncrypted, onChange: (e_6) => {
        setIsEncrypted(e_6.currentTarget.checked);
        resetValidation();
      }, disabled: true }),
      validationError && /* @__PURE__ */ jsxRuntimeExports.jsx(Alert, { icon: /* @__PURE__ */ jsxRuntimeExports.jsx(IconAlertCircle, { size: "1rem" }), color: "red", variant: "light", children: validationError }),
      isValidated && !validationError && /* @__PURE__ */ jsxRuntimeExports.jsx(Alert, { color: "green", variant: "light", children: t("storagePage.createDialog.validationSuccess") })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.actionsWrapper, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.actions, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { label: getSaveTooltip(), disabled: !getSaveTooltip() || isLoading, withArrow: true, position: "top", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { maw: "fit-content", fullWidth: true, onClick: handleSave, variant: "light", disabled: !isFormValid() || !isValidated || isLoading, loading: isLoading, children: t("storagePage.editDialog.saveButton") }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { maw: "fit-content", fullWidth: true, onClick: handleCancel, variant: "light", color: "gray", disabled: isLoading, children: t("storagePage.editDialog.cancelButton") })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { label: getValidateTooltip(), disabled: !getValidateTooltip() || isValidating || isLoading, withArrow: true, position: "top", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: false, onClick: handleValidate, variant: "outline", color: "blue", disabled: !isFormValid() || isValidating || isLoading, loading: isValidating, children: t("storagePage.createDialog.validateButton") }) })
    ] })
  ] });
};
const ClearStorageDataDialog = (props) => {
  const {
    t
  } = useTranslation();
  const {
    handleClosePopUp,
    storageId,
    onSuccess
  } = props;
  const [isLoading, setIsLoading] = reactExports.useState(false);
  const handleDelete = async () => {
    try {
      setIsLoading(true);
      await storageConfigurationApiArea().DeleteStorageConfiguration({
        id: storageId
      });
      if (onSuccess) {
        await onSuccess();
      }
      handleClosePopUp();
    } catch (error) {
    } finally {
      setIsLoading(false);
    }
  };
  const handleCancel = () => {
    handleClosePopUp();
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.removeDialog, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.removeDialogQuestion, children: "Файлы подразделений, не имеющих доступа к текущему хранилищу, будут удалены без возможности восстановления." }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.removeDialogActions, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "gray", variant: "light", onClick: handleCancel, disabled: isLoading, children: t("storagePage.deleteDialog.cancelButton") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "red", variant: "light", onClick: handleDelete, loading: isLoading, disabled: isLoading, children: t("storagePage.deleteDialog.deleteButton") })
    ] })
  ] });
};
const StorageActionsTrigger = (props) => {
  const $ = compilerRuntimeExports.c(8);
  const {
    setIsOpen,
    disabled
  } = props;
  let t0;
  if ($[0] !== setIsOpen) {
    t0 = () => setIsOpen(true);
    $[0] = setIsOpen;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const handleOpen = t0;
  const t1 = disabled ? "#ccc" : "#667085";
  let t2;
  if ($[2] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(IconDotsVertical, { color: t1, size: 18 });
    $[2] = t1;
    $[3] = t2;
  } else {
    t2 = $[3];
  }
  let t3;
  if ($[4] !== disabled || $[5] !== handleOpen || $[6] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { mr: 0, disabled, "data-cy": "moreActionsBtn", onClick: handleOpen, children: t2 });
    $[4] = disabled;
    $[5] = handleOpen;
    $[6] = t2;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  return t3;
};
const StorageEditTrigger = (props) => {
  const $ = compilerRuntimeExports.c(9);
  const {
    setIsOpen,
    disabled
  } = props;
  let t0;
  if ($[0] !== disabled || $[1] !== setIsOpen) {
    t0 = () => {
      if (!disabled) {
        setIsOpen(true);
      }
    };
    $[0] = disabled;
    $[1] = setIsOpen;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  const handleOpen = t0;
  const t1 = disabled ? "#ccc" : "#667085";
  let t2;
  if ($[3] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(IconEdit, { color: t1, size: 18 });
    $[3] = t1;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  let t3;
  if ($[5] !== disabled || $[6] !== handleOpen || $[7] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { mr: 0, "data-cy": "moreActionsBtn", onClick: handleOpen, disabled, children: t2 });
    $[5] = disabled;
    $[6] = handleOpen;
    $[7] = t2;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  return t3;
};
const TransferDataTrigger = (props) => {
  const $ = compilerRuntimeExports.c(19);
  const {
    t
  } = useTranslation();
  const {
    setIsOpen,
    disabled
  } = props;
  let t0;
  if ($[0] !== disabled || $[1] !== setIsOpen) {
    t0 = () => {
      if (!disabled) {
        setIsOpen(true);
      }
    };
    $[0] = disabled;
    $[1] = setIsOpen;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  const handleOpen = t0;
  let t1;
  if ($[3] !== disabled || $[4] !== t) {
    t1 = disabled ? t("storagePage.actions.transferDisabled") : t("storagePage.actions.transferDescription");
    $[3] = disabled;
    $[4] = t;
    $[5] = t1;
  } else {
    t1 = $[5];
  }
  const t2 = disabled ? "transparent" : "";
  let t3;
  if ($[6] !== t2) {
    t3 = {
      background: t2
    };
    $[6] = t2;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  let t4;
  if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(IconBrandCitymapper, {});
    $[8] = t4;
  } else {
    t4 = $[8];
  }
  let t5;
  if ($[9] !== t) {
    t5 = t("storagePage.actions.transfer");
    $[9] = t;
    $[10] = t5;
  } else {
    t5 = $[10];
  }
  let t6;
  if ($[11] !== disabled || $[12] !== handleOpen || $[13] !== t3 || $[14] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, onClick: handleOpen, style: t3, size: "sm", justify: "flex-start", color: "gray", variant: "transparent", leftSection: t4, disabled, children: t5 });
    $[11] = disabled;
    $[12] = handleOpen;
    $[13] = t3;
    $[14] = t5;
    $[15] = t6;
  } else {
    t6 = $[15];
  }
  let t7;
  if ($[16] !== t1 || $[17] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { withArrow: true, zIndex: 1e3, label: t1, children: t6 });
    $[16] = t1;
    $[17] = t6;
    $[18] = t7;
  } else {
    t7 = $[18];
  }
  return t7;
};
const RemoveStorageTrigger = (props) => {
  const $ = compilerRuntimeExports.c(20);
  const {
    t
  } = useTranslation();
  const {
    setIsOpen,
    disabled,
    reason
  } = props;
  let t0;
  if ($[0] !== disabled || $[1] !== setIsOpen) {
    t0 = () => {
      if (!disabled) {
        setIsOpen(true);
      }
    };
    $[0] = disabled;
    $[1] = setIsOpen;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  const handleOpen = t0;
  let t1;
  if ($[3] !== disabled || $[4] !== reason || $[5] !== t) {
    t1 = disabled ? reason || t("storagePage.actions.cannotDelete") : t("storagePage.actions.deleteDescription");
    $[3] = disabled;
    $[4] = reason;
    $[5] = t;
    $[6] = t1;
  } else {
    t1 = $[6];
  }
  const label = t1;
  const t2 = disabled ? "transparent" : "";
  let t3;
  if ($[7] !== t2) {
    t3 = {
      background: t2
    };
    $[7] = t2;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  let t4;
  if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(IconTrash, {});
    $[9] = t4;
  } else {
    t4 = $[9];
  }
  let t5;
  if ($[10] !== t) {
    t5 = t("storagePage.actions.delete");
    $[10] = t;
    $[11] = t5;
  } else {
    t5 = $[11];
  }
  let t6;
  if ($[12] !== disabled || $[13] !== handleOpen || $[14] !== t3 || $[15] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "rgba(224, 49, 49, 0.6)", style: t3, onClick: handleOpen, justify: "flex-start", size: "sm", variant: "transparent", leftSection: t4, disabled, children: t5 });
    $[12] = disabled;
    $[13] = handleOpen;
    $[14] = t3;
    $[15] = t5;
    $[16] = t6;
  } else {
    t6 = $[16];
  }
  let t7;
  if ($[17] !== label || $[18] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { withArrow: true, zIndex: 1e3, label, children: t6 });
    $[17] = label;
    $[18] = t6;
    $[19] = t7;
  } else {
    t7 = $[19];
  }
  return t7;
};
const ClearStorageTrigger = (props) => {
  const $ = compilerRuntimeExports.c(20);
  const {
    t
  } = useTranslation();
  const {
    setIsOpen,
    disabled,
    reason
  } = props;
  let t0;
  if ($[0] !== disabled || $[1] !== setIsOpen) {
    t0 = () => {
      if (!disabled) {
        setIsOpen(true);
      }
    };
    $[0] = disabled;
    $[1] = setIsOpen;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  const handleOpen = t0;
  let t1;
  if ($[3] !== disabled || $[4] !== reason || $[5] !== t) {
    t1 = disabled ? reason || t("storagePage.actions.cannotDelete") : t("storagePage.actions.clearDescription");
    $[3] = disabled;
    $[4] = reason;
    $[5] = t;
    $[6] = t1;
  } else {
    t1 = $[6];
  }
  const label = t1;
  const t2 = disabled ? "transparent" : "";
  let t3;
  if ($[7] !== t2) {
    t3 = {
      background: t2
    };
    $[7] = t2;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  let t4;
  if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(sZ, {});
    $[9] = t4;
  } else {
    t4 = $[9];
  }
  let t5;
  if ($[10] !== t) {
    t5 = t("storagePage.actions.clear");
    $[10] = t;
    $[11] = t5;
  } else {
    t5 = $[11];
  }
  let t6;
  if ($[12] !== disabled || $[13] !== handleOpen || $[14] !== t3 || $[15] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, onClick: handleOpen, style: t3, justify: "flex-start", size: "sm", variant: "transparent", color: "gray", leftSection: t4, disabled, children: t5 });
    $[12] = disabled;
    $[13] = handleOpen;
    $[14] = t3;
    $[15] = t5;
    $[16] = t6;
  } else {
    t6 = $[16];
  }
  let t7;
  if ($[17] !== label || $[18] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { withArrow: true, zIndex: 1e3, label, children: t6 });
    $[17] = label;
    $[18] = t6;
    $[19] = t7;
  } else {
    t7 = $[19];
  }
  return t7;
};
const ProgressTrigger = (props) => {
  const $ = compilerRuntimeExports.c(14);
  const {
    setIsOpen,
    migrationProgress,
    hasError
  } = props;
  let t0;
  if ($[0] !== setIsOpen) {
    t0 = () => setIsOpen(true);
    $[0] = setIsOpen;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const handleOpen = t0;
  const t1 = hasError ? "#ffe9e9" : "";
  let t2;
  if ($[2] !== t1) {
    t2 = {
      background: t1
    };
    $[2] = t1;
    $[3] = t2;
  } else {
    t2 = $[3];
  }
  let t3;
  if ($[4] !== migrationProgress) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { fw: 500, children: [
      migrationProgress,
      "%"
    ] });
    $[4] = migrationProgress;
    $[5] = t3;
  } else {
    t3 = $[5];
  }
  const t4 = migrationProgress || 0;
  const t5 = hasError ? "red" : void 0;
  let t6;
  if ($[6] !== t4 || $[7] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Progress, { value: t4, color: t5 });
    $[6] = t4;
    $[7] = t5;
    $[8] = t6;
  } else {
    t6 = $[8];
  }
  let t7;
  if ($[9] !== handleOpen || $[10] !== t2 || $[11] !== t3 || $[12] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { onClick: handleOpen, className: classes.progressWrapper, style: t2, children: [
      t3,
      t6
    ] });
    $[9] = handleOpen;
    $[10] = t2;
    $[11] = t3;
    $[12] = t6;
    $[13] = t7;
  } else {
    t7 = $[13];
  }
  return t7;
};
const getStorageTypeLabel = (type, t) => {
  switch (type) {
    case StorageType.S3:
      return t("storagePage.storageTypes.s3");
    case StorageType.Fs:
      return t("storagePage.storageTypes.fileStorage");
    case StorageType.S3Encrypted:
      return t("storagePage.storageTypes.s3Encrypted");
    case StorageType.FsEncrypted:
      return t("storagePage.storageTypes.fileStorageEncrypted");
    default:
      return t("storagePage.storageTypes.unknown");
  }
};
function StorageTableRowItem(props) {
  const {
    t
  } = useTranslation();
  const {
    element,
    onUpdate
  } = props;
  const [migrationProgress, setMigrationProgress] = reactExports.useState(null);
  const [isLoading, setIsLoading] = reactExports.useState(false);
  const [activeMigrationId, setActiveMigrationId] = reactExports.useState(null);
  const [showMigrationProgress, setShowMigrationProgress] = reactExports.useState(false);
  const [isEnabled, setIsEnabled] = reactExports.useState(element.IsEnabled);
  const [migrationError, setMigrationError] = reactExports.useState(false);
  const [toStorageId, setToStorageId] = reactExports.useState(null);
  const [storages, setStorages] = reactExports.useState([]);
  const pollingIntervalRef = reactExports.useRef(null);
  const handleMigrationStarted = (migrationId, targetStorageId) => {
    setActiveMigrationId(migrationId);
    setShowMigrationProgress(true);
    setMigrationProgress(0);
    setMigrationError(false);
    if (targetStorageId !== void 0) {
      setToStorageId(targetStorageId);
    }
    const activeMigrations = JSON.parse(localStorage.getItem("activeMigrations") || "{}");
    activeMigrations[element.Id] = {
      taskId: migrationId,
      toStorageId: targetStorageId
    };
    localStorage.setItem("activeMigrations", JSON.stringify(activeMigrations));
  };
  const handleMigrationComplete = (showSuccessNotification = false) => {
    if (showSuccessNotification && toStorageId) {
      const fromStorage = storages.find((s) => s.Id === element.Id);
      const toStorage = storages.find((s_0) => s_0.Id === toStorageId);
      if (fromStorage && toStorage) {
        showNotification({
          title: t("storagePage.notifications.migrationCompleted", {
            from: fromStorage.Name,
            to: toStorage.Name
          }),
          message: "",
          autoClose: 5e3,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
      } else {
        showNotification({
          title: t("storagePage.notifications.migrationCompletedSimple"),
          message: "",
          autoClose: 5e3,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
      }
    }
    setActiveMigrationId(null);
    setShowMigrationProgress(false);
    setMigrationProgress(null);
    setToStorageId(null);
    const activeMigrations_0 = JSON.parse(localStorage.getItem("activeMigrations") || "{}");
    delete activeMigrations_0[element.Id];
    localStorage.setItem("activeMigrations", JSON.stringify(activeMigrations_0));
    if (onUpdate) {
      onUpdate();
    }
  };
  const handleProgressUpdate = (percent) => {
    setMigrationProgress(percent);
  };
  const handleCancelMigration = async () => {
    try {
      setIsLoading(true);
      await storageConfigurationApiArea().CancelMigration({
        id: element.Id
      });
      handleMigrationComplete();
    } catch (error) {
    } finally {
      setIsLoading(false);
    }
  };
  reactExports.useEffect(() => {
    const fetchStorages = async () => {
      try {
        const data = await storageConfigurationApiArea().GetStorageConfigurations();
        setStorages(data);
      } catch (error_0) {
      }
    };
    void fetchStorages();
  }, []);
  reactExports.useEffect(() => {
    const checkActiveMigration = async () => {
      try {
        try {
          const data_0 = await storageConfigurationApiArea().GetMigrationStatus({
            id: element.Id
          });
          const isActiveMigration = (data_0.Status === UserTaskStatus.Register || data_0.Status === UserTaskStatus.Start || data_0.Status === UserTaskStatus.DoneWithErrors) && data_0.Percent < 100;
          if (isActiveMigration) {
            setActiveMigrationId(data_0.TaskId);
            setShowMigrationProgress(true);
            setMigrationProgress(data_0.Percent);
            const activeMigrations_2 = JSON.parse(localStorage.getItem("activeMigrations") || "{}");
            const migrationInfo = activeMigrations_2[element.Id];
            if (migrationInfo && migrationInfo.toStorageId !== void 0) {
              setToStorageId(migrationInfo.toStorageId);
            }
            activeMigrations_2[element.Id] = {
              taskId: data_0.TaskId,
              toStorageId: migrationInfo == null ? void 0 : migrationInfo.toStorageId
            };
            localStorage.setItem("activeMigrations", JSON.stringify(activeMigrations_2));
          } else if (data_0.Status === UserTaskStatus.Done || data_0.Percent >= 100) {
            const activeMigrations_3 = JSON.parse(localStorage.getItem("activeMigrations") || "{}");
            delete activeMigrations_3[element.Id];
            localStorage.setItem("activeMigrations", JSON.stringify(activeMigrations_3));
          }
        } catch (error_2) {
          const activeMigrations_1 = JSON.parse(localStorage.getItem("activeMigrations") || "{}");
          delete activeMigrations_1[element.Id];
          localStorage.setItem("activeMigrations", JSON.stringify(activeMigrations_1));
        }
      } catch (error_1) {
      }
    };
    void checkActiveMigration();
  }, [element.Id]);
  reactExports.useEffect(() => {
    const stopPolling = () => {
      if (pollingIntervalRef.current) {
        clearInterval(pollingIntervalRef.current);
        pollingIntervalRef.current = null;
      }
    };
    if (activeMigrationId === null || !showMigrationProgress) {
      stopPolling();
      return;
    }
    const fetchMigrationStatus = async () => {
      try {
        const data_1 = await storageConfigurationApiArea().GetMigrationStatus({
          id: element.Id
        });
        setMigrationProgress(data_1.Percent);
        const isCompleted = data_1.Status === UserTaskStatus.Done || data_1.Percent >= 100;
        const isCanceled = data_1.Status === UserTaskStatus.Canceled;
        const isError = data_1.Status === UserTaskStatus.Error;
        const hasErrors = data_1.Status === UserTaskStatus.DoneWithErrors;
        if (isError || isCanceled || hasErrors) {
          setMigrationError(true);
          stopPolling();
        } else {
          setMigrationError(false);
        }
        if (isCompleted && !hasErrors) {
          stopPolling();
          setTimeout(() => {
            handleMigrationComplete(true);
          }, 1e3);
        }
      } catch (error_3) {
        stopPolling();
        handleMigrationComplete(false);
      }
    };
    void fetchMigrationStatus();
    pollingIntervalRef.current = setInterval(fetchMigrationStatus, 3e3);
    return () => {
      stopPolling();
    };
  }, [activeMigrationId, showMigrationProgress]);
  const canDelete = !element.IsDefault && !element.HaveFiles && !showMigrationProgress;
  const deleteReason = element.IsDefault ? t("storagePage.actions.deleteDefaultDisabled") : element.HaveFiles ? t("storagePage.actions.deleteHasFilesDisabled") : showMigrationProgress ? t("storagePage.actions.migrationInProgress") : void 0;
  const canMigrate = !element.IsDefault && !showMigrationProgress;
  const canEdit = !showMigrationProgress;
  const handleToggleEnabled = async () => {
    const newIsEnabled = !isEnabled;
    try {
      setIsEnabled(newIsEnabled);
      setIsLoading(true);
      await storageConfigurationApiArea().SetStorageEnabled({
        id: element.Id,
        value: newIsEnabled
      });
    } catch (error_4) {
      setIsEnabled(!newIsEnabled);
    } finally {
      setIsLoading(false);
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Table.Tr, { style: {
    position: "relative"
  }, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Td, { className: classes.tableCell, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: element.Name }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Td, { className: classes.tableCell, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: getStorageTypeLabel(element.Type, t) }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Td, { className: classes.tableCell, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Switch, { color: "green", checked: isEnabled, onChange: handleToggleEnabled, disabled: element.IsDefault || showMigrationProgress }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Td, { className: classes.tableCell, children: showMigrationProgress && activeMigrationId !== null && /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { align: "center", gap: 8, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "90%", desktopPosition: "left-start", trigger: (props_0) => /* @__PURE__ */ jsxRuntimeExports.jsx(ProgressTrigger, { ...props_0, migrationProgress: migrationProgress || 0, hasError: migrationError }), children: (progressPopup) => /* @__PURE__ */ jsxRuntimeExports.jsx(MigrationProgressDialog, { ...progressPopup, storageId: element.Id, fromStorageId: element.Id, toStorageId: toStorageId || 0, onSuccess: handleMigrationComplete, onCancel: handleMigrationComplete, onProgressUpdate: handleProgressUpdate, onRetry: (newTaskId) => handleMigrationStarted(newTaskId, toStorageId || 0) }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { label: t("storagePage.actions.cancelMigration"), withArrow: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { onClick: handleCancelMigration, variant: "subtle", color: "red", disabled: isLoading, children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconX, { size: 18 }) }) })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Table.Td, { className: classes.tableCell, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "flex-end", align: "center", gap: 8, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "100%", desktopPosition: "left-start", trigger: (props_1) => /* @__PURE__ */ jsxRuntimeExports.jsx(StorageEditTrigger, { ...props_1, disabled: !canEdit }), children: (params) => /* @__PURE__ */ jsxRuntimeExports.jsx(EditStorageDialog, { ...params, itemToEditId: element.Id, onSuccess: onUpdate }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "100%", desktopPosition: "right-start", trigger: (props_2) => /* @__PURE__ */ jsxRuntimeExports.jsx(StorageActionsTrigger, { ...props_2, disabled: !canEdit }), children: /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "90%", desktopPosition: "left-start", trigger: (props_3) => /* @__PURE__ */ jsxRuntimeExports.jsx(TransferDataTrigger, { ...props_3, disabled: !canMigrate }), children: (transferPopup) => /* @__PURE__ */ jsxRuntimeExports.jsx(TransferDialog, { ...transferPopup, fromStorageId: element.Id, onSuccess: onUpdate, onMigrationStarted: handleMigrationStarted }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "90%", desktopPosition: "left-start", trigger: (props_4) => /* @__PURE__ */ jsxRuntimeExports.jsx(ClearStorageTrigger, { ...props_4, disabled: !canDelete, reason: deleteReason }), children: (deletePopup) => /* @__PURE__ */ jsxRuntimeExports.jsx(ClearStorageDataDialog, { ...deletePopup, storageId: element.Id, onSuccess: onUpdate }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "90%", desktopPosition: "left-start", trigger: (props_5) => /* @__PURE__ */ jsxRuntimeExports.jsx(RemoveStorageTrigger, { ...props_5, disabled: !canDelete, reason: deleteReason }), children: (deletePopup_0) => /* @__PURE__ */ jsxRuntimeExports.jsx(DeleteDialog, { ...deletePopup_0, storageId: element.Id, onSuccess: onUpdate }) })
        ] }) })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isLoading, style: {
        position: "absolute",
        zIndex: 20
      } })
    ] })
  ] });
}
function StorageTable(props) {
  const $ = compilerRuntimeExports.c(42);
  const {
    t
  } = useTranslation();
  const {
    storages,
    onUpdate
  } = props;
  const isMobile = useMediaQuery("(max-width: 576px)");
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = {
      tableLayout: "fixed"
    };
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const t1 = isMobile ? "50%" : "30%";
  let t2;
  if ($[1] !== t1) {
    t2 = {
      width: t1
    };
    $[1] = t1;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  let t3;
  if ($[3] !== t) {
    t3 = t("storagePage.table.nameHeader");
    $[3] = t;
    $[4] = t3;
  } else {
    t3 = $[4];
  }
  let t4;
  if ($[5] !== t2 || $[6] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Th, { className: classes$1.headerCell, style: t2, children: t3 });
    $[5] = t2;
    $[6] = t3;
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  const t5 = isMobile ? "30%" : "20%";
  let t6;
  if ($[8] !== t5) {
    t6 = {
      width: t5
    };
    $[8] = t5;
    $[9] = t6;
  } else {
    t6 = $[9];
  }
  let t7;
  if ($[10] !== t) {
    t7 = t("storagePage.table.typeHeader");
    $[10] = t;
    $[11] = t7;
  } else {
    t7 = $[11];
  }
  let t8;
  if ($[12] !== t6 || $[13] !== t7) {
    t8 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Th, { className: classes$1.headerCell, style: t6, children: t7 });
    $[12] = t6;
    $[13] = t7;
    $[14] = t8;
  } else {
    t8 = $[14];
  }
  const t9 = isMobile ? "20%" : "10%";
  let t10;
  if ($[15] !== t9) {
    t10 = {
      width: t9
    };
    $[15] = t9;
    $[16] = t10;
  } else {
    t10 = $[16];
  }
  let t11;
  if ($[17] !== t) {
    t11 = t("storagePage.table.activityHeader");
    $[17] = t;
    $[18] = t11;
  } else {
    t11 = $[18];
  }
  let t12;
  if ($[19] !== t10 || $[20] !== t11) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Th, { className: classes$1.headerCell, style: t10, children: t11 });
    $[19] = t10;
    $[20] = t11;
    $[21] = t12;
  } else {
    t12 = $[21];
  }
  const t13 = isMobile ? "25%" : "10%";
  let t14;
  if ($[22] !== t13) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Th, { className: classes$1.headerCell, style: {
      width: t13
    } });
    $[22] = t13;
    $[23] = t14;
  } else {
    t14 = $[23];
  }
  const t15 = isMobile ? "15%" : "10%";
  let t16;
  if ($[24] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Th, { className: classes$1.headerCell, style: {
      width: t15
    } });
    $[24] = t15;
    $[25] = t16;
  } else {
    t16 = $[25];
  }
  let t17;
  if ($[26] !== t12 || $[27] !== t14 || $[28] !== t16 || $[29] !== t4 || $[30] !== t8) {
    t17 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Thead, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Table.Tr, { children: [
      t4,
      t8,
      t12,
      t14,
      t16
    ] }) });
    $[26] = t12;
    $[27] = t14;
    $[28] = t16;
    $[29] = t4;
    $[30] = t8;
    $[31] = t17;
  } else {
    t17 = $[31];
  }
  let t18;
  if ($[32] !== onUpdate || $[33] !== storages) {
    let t192;
    if ($[35] !== onUpdate) {
      t192 = (element) => /* @__PURE__ */ jsxRuntimeExports.jsx(StorageTableRowItem, { element, onUpdate }, element.Id);
      $[35] = onUpdate;
      $[36] = t192;
    } else {
      t192 = $[36];
    }
    t18 = storages.map(t192);
    $[32] = onUpdate;
    $[33] = storages;
    $[34] = t18;
  } else {
    t18 = $[34];
  }
  let t19;
  if ($[37] !== t18) {
    t19 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Tbody, { children: t18 });
    $[37] = t18;
    $[38] = t19;
  } else {
    t19 = $[38];
  }
  let t20;
  if ($[39] !== t17 || $[40] !== t19) {
    t20 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Table, { style: t0, children: [
      t17,
      t19
    ] });
    $[39] = t17;
    $[40] = t19;
    $[41] = t20;
  } else {
    t20 = $[41];
  }
  return t20;
}
const MakeStorageDialog = (props) => {
  const {
    t
  } = useTranslation();
  const {
    onSuccess,
    handleClosePopUp
  } = props;
  const [isLoading, setIsLoading] = reactExports.useState(false);
  const [isValidating, setIsValidating] = reactExports.useState(false);
  const [isValidated, setIsValidated] = reactExports.useState(false);
  const [validationError, setValidationError] = reactExports.useState(null);
  const TypeOptions = [{
    label: t("storagePage.storageTypes.s3"),
    value: "S3"
  }, {
    label: t("storagePage.storageTypes.fileStorage"),
    value: "Fs"
  }];
  const [name, setName] = reactExports.useState("");
  const [baseType, setBaseType] = reactExports.useState("S3");
  const [isEncrypted, setIsEncrypted] = reactExports.useState(false);
  const [s3Key, setS3Key] = reactExports.useState("");
  const [s3Secret, setS3Secret] = reactExports.useState("");
  const [s3SystemName, setS3SystemName] = reactExports.useState("");
  const [s3Url, setS3Url] = reactExports.useState("");
  const [s3Bucket, setS3Bucket] = reactExports.useState("");
  const [fsUrl, setFsUrl] = reactExports.useState("");
  const resetValidation = () => {
    setIsValidated(false);
    setValidationError(null);
  };
  const onChange = (value) => {
    if (value === "S3" || value === "Fs") {
      setBaseType(value);
      resetValidation();
    }
  };
  const getBaseStorageType = () => {
    return baseType === "S3" ? StorageType.S3 : StorageType.Fs;
  };
  const isS3Type = baseType === "S3";
  const isFsType = baseType === "Fs";
  const handleValidate = async () => {
    try {
      setIsValidating(true);
      setValidationError(null);
      const storageType = getBaseStorageType();
      let result;
      if (isS3Type) {
        result = await storageConfigurationApiArea().ValidateStorageConfiguration({
          Name: name,
          Type: storageType,
          S3ConfigurationSettings: {
            Key: s3Key,
            Secret: s3Secret,
            SystemName: s3SystemName,
            Bucket: s3Bucket,
            Url: s3Url
          },
          IsEncrypted: isEncrypted
        });
      } else if (isFsType) {
        result = await storageConfigurationApiArea().ValidateStorageConfiguration({
          Name: name,
          Type: storageType,
          FsConfigurationSettings: {
            Host: fsUrl
          },
          IsEncrypted: isEncrypted
        });
      } else {
        return false;
      }
      if (result.Success) {
        setIsValidated(true);
        setValidationError(null);
        return true;
      } else {
        setIsValidated(false);
        let errorMessage_0 = "Validation failed";
        if (result.Details && result.Details.Errors.length > 0) {
          errorMessage_0 = result.Details.Errors.join("; ");
        } else if (result.FailedValidation.length > 0) {
          errorMessage_0 = `Validation failed for: ${result.FailedValidation.join(", ")}`;
        }
        setValidationError(errorMessage_0);
        return false;
      }
    } catch (error) {
      const errorMessage = error instanceof Error ? error.message : "Unknown validation error";
      setIsValidated(false);
      setValidationError(errorMessage);
      showNotification({
        title: t("storagePage.notifications.storageCreateError"),
        message: errorMessage,
        autoClose: true,
        color: "red",
        style: {
          zIndex: 1003
        }
      });
      return false;
    } finally {
      setIsValidating(false);
    }
  };
  const handleSave = async () => {
    try {
      setIsLoading(true);
      if (!isValidated) {
        const validationResult = await handleValidate();
        if (!validationResult) {
          setIsLoading(false);
          return;
        }
      }
      const storageType_0 = getBaseStorageType();
      if (isS3Type) {
        await storageConfigurationApiArea().CreateStorageConfiguration({
          Name: name,
          Type: storageType_0,
          S3ConfigurationSettings: {
            Key: s3Key,
            Secret: s3Secret,
            SystemName: s3SystemName,
            Bucket: s3Bucket,
            Url: s3Url
          },
          IsEncrypted: isEncrypted
        });
      } else if (isFsType) {
        await storageConfigurationApiArea().CreateStorageConfiguration({
          Name: name,
          Type: storageType_0,
          FsConfigurationSettings: {
            Host: fsUrl
          },
          IsEncrypted: isEncrypted
        });
      }
      showNotification({
        title: t("storagePage.notifications.storageCreated"),
        message: "",
        autoClose: true,
        color: "green",
        style: {
          zIndex: 1003
        }
      });
      if (onSuccess) {
        await onSuccess();
      }
      handleClosePopUp();
    } catch (error_0) {
      showNotification({
        title: t("storagePage.notifications.storageCreateError"),
        message: error_0 instanceof Error ? error_0.message : "",
        autoClose: true,
        color: "red",
        style: {
          zIndex: 1003
        }
      });
    } finally {
      setIsLoading(false);
    }
  };
  const handleCancel = () => {
    handleClosePopUp();
  };
  const isFormValid = () => {
    if (!name) return false;
    if (isS3Type) {
      return s3Key && s3Secret && s3SystemName && s3Bucket && s3Url;
    }
    if (isFsType) {
      return fsUrl;
    }
    return false;
  };
  const getValidateTooltip = () => {
    if (!isFormValid()) {
      return t("storagePage.createDialog.tooltips.fillRequiredFields");
    }
    return "";
  };
  const getCreateTooltip = () => {
    if (!isFormValid()) {
      return t("storagePage.createDialog.tooltips.fillRequiredFields");
    }
    if (!isValidated) {
      return t("storagePage.createDialog.tooltips.validateFirst");
    }
    return "";
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.container, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.form, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { gap: "md", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", gap: "md", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { style: {
          flex: 1
        }, value: baseType, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconChevronDown, { size: "1rem", color: "#98A2B3" }), onChange, data: TypeOptions, label: t("storagePage.createDialog.typeLabel"), placeholder: t("storagePage.createDialog.typePlaceholder"), comboboxProps: {
          transitionProps: {
            transition: "pop",
            duration: 200
          },
          offset: -20,
          withinPortal: false
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { style: {
          flex: 1
        }, placeholder: t("storagePage.createDialog.namePlaceholder"), label: t("storagePage.createDialog.nameLabel"), withAsterisk: true, value: name, onChange: (e) => {
          setName(e.target.value);
          resetValidation();
        } })
      ] }),
      isS3Type && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3KeyPlaceholder"), label: t("storagePage.createDialog.s3KeyLabel"), withAsterisk: true, value: s3Key, onChange: (e_0) => {
          setS3Key(e_0.target.value);
          resetValidation();
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3SecretPlaceholder"), label: t("storagePage.createDialog.s3SecretLabel"), withAsterisk: true, type: "password", value: s3Secret, onChange: (e_1) => {
          setS3Secret(e_1.target.value);
          resetValidation();
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3SystemNamePlaceholder"), label: t("storagePage.createDialog.s3SystemNameLabel"), withAsterisk: true, value: s3SystemName, onChange: (e_2) => {
          setS3SystemName(e_2.target.value);
          resetValidation();
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3UrlPlaceholder"), label: t("storagePage.createDialog.s3UrlLabel"), withAsterisk: true, value: s3Url, onChange: (e_3) => {
          setS3Url(e_3.target.value);
          resetValidation();
        } }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.s3BucketPlaceholder"), label: t("storagePage.createDialog.s3BucketLabel"), withAsterisk: true, value: s3Bucket, onChange: (e_4) => {
          setS3Bucket(e_4.target.value);
          resetValidation();
        } })
      ] }),
      isFsType && /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t("storagePage.createDialog.fsUrlPlaceholder"), label: t("storagePage.createDialog.fsUrlLabel"), withAsterisk: true, value: fsUrl, onChange: (e_5) => {
        setFsUrl(e_5.target.value);
        resetValidation();
      } }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { label: t("storagePage.createDialog.enableEncryption"), checked: isEncrypted, onChange: (e_6) => {
        setIsEncrypted(e_6.currentTarget.checked);
        resetValidation();
      } }),
      validationError && /* @__PURE__ */ jsxRuntimeExports.jsx(Alert, { icon: /* @__PURE__ */ jsxRuntimeExports.jsx(IconAlertCircle, { size: "1rem" }), color: "red", variant: "light", children: validationError }),
      isValidated && !validationError && /* @__PURE__ */ jsxRuntimeExports.jsx(Alert, { color: "green", variant: "light", children: t("storagePage.createDialog.validationSuccess") })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.actionsWrapper, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.actions, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { label: getCreateTooltip(), disabled: !getCreateTooltip() || isLoading, withArrow: true, position: "top", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { maw: "fit-content", fullWidth: true, onClick: handleSave, variant: "light", disabled: !isFormValid() || !isValidated || isLoading, loading: isLoading, children: t("storagePage.createDialog.createButton") }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { maw: "fit-content", fullWidth: true, onClick: handleCancel, variant: "light", color: "gray", disabled: isLoading, children: t("storagePage.createDialog.cancelButton") })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { label: getValidateTooltip(), disabled: !getValidateTooltip() || isValidating || isLoading, withArrow: true, position: "top", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: false, onClick: handleValidate, variant: "outline", color: "blue", disabled: !isFormValid() || isValidating || isLoading, loading: isValidating, children: t("storagePage.createDialog.validateButton") }) })
    ] })
  ] });
};
const CreateStorageTrigger = (t0) => {
  const $ = compilerRuntimeExports.c(5);
  const {
    handleOpenPopUp
  } = t0;
  const {
    t
  } = useTranslation();
  let t1;
  if ($[0] !== t) {
    t1 = t("storagePage.createButton");
    $[0] = t;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  let t2;
  if ($[2] !== handleOpenPopUp || $[3] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { onClick: handleOpenPopUp, children: t1 });
    $[2] = handleOpenPopUp;
    $[3] = t1;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  return t2;
};
const StoragePage = () => {
  const $ = compilerRuntimeExports.c(14);
  const {
    t
  } = useTranslation();
  const context = useStoragePage();
  const {
    isLoading,
    storages,
    fetchStorages
  } = context;
  if (isLoading) {
    let t02;
    if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
      t02 = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.loadingContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { color: "blue" }) });
      $[0] = t02;
    } else {
      t02 = $[0];
    }
    return t02;
  }
  let t0;
  if ($[1] !== t) {
    t0 = t("storagePage.title");
    $[1] = t;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  let t1;
  if ($[3] !== t0) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$2.title, children: t0 });
    $[3] = t0;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  let t2;
  if ($[5] !== fetchStorages || $[6] !== storages) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(StorageTable, { storages, onUpdate: fetchStorages });
    $[5] = fetchStorages;
    $[6] = storages;
    $[7] = t2;
  } else {
    t2 = $[7];
  }
  let t3;
  if ($[8] !== fetchStorages) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "90%", desktopPosition: "right-start", trigger: _temp, children: (popupProps) => /* @__PURE__ */ jsxRuntimeExports.jsx(MakeStorageDialog, { ...popupProps, onSuccess: fetchStorages }) });
    $[8] = fetchStorages;
    $[9] = t3;
  } else {
    t3 = $[9];
  }
  let t4;
  if ($[10] !== t1 || $[11] !== t2 || $[12] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes$2.container, children: [
      t1,
      t2,
      t3
    ] });
    $[10] = t1;
    $[11] = t2;
    $[12] = t3;
    $[13] = t4;
  } else {
    t4 = $[13];
  }
  return t4;
};
function _temp(props) {
  return /* @__PURE__ */ jsxRuntimeExports.jsx(CreateStorageTrigger, { ...props });
}
export {
  StoragePage as default
};
//# sourceMappingURL=index-BDxz8DSx.js.map
