import { r as reactExports } from "./vendor-react-DYNCg6N5.js";
import { ba as useUpdateFilialSettingsMutation, b as useActions, ac as useLazyGetFilialsInfoCommonQuery, m as universalNotification } from "./index-DfebxkL9.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
const useSaveSettings = () => {
  const {
    t
  } = useTranslation();
  const [updateSettings] = useUpdateFilialSettingsMutation();
  const {
    setFilial
  } = useActions();
  const [getUpdatedValue, {
    isSuccess,
    data: updatedData
  }] = useLazyGetFilialsInfoCommonQuery();
  return reactExports.useCallback(async (id, type, values) => {
    try {
      const res = await updateSettings({
        id,
        type,
        ...values
      });
      if ("error" in res) {
        universalNotification({
          error: `${res == null ? void 0 : res.error}`,
          isError: true,
          isSuccess: false
        });
      } else {
        universalNotification({
          successTitle: t("filials.successSave"),
          isSuccess: true,
          isError: false,
          error: null
        });
        getUpdatedValue({
          id,
          extended: true
        });
        if (id && isSuccess && updatedData) {
          setFilial(updatedData);
        }
      }
    } catch (err) {
      console.warn(t("filials.errors.save"), err);
    }
  }, []);
};
export {
  useSaveSettings as u
};
//# sourceMappingURL=useSaveSettings-GkZlPEM1.js.map
