'use strict';

var reactQuery = require('@tanstack/react-query');
var axios = require('axios');
var react = require('@chakra-ui/react');
var jsxRuntime = require('react/jsx-runtime');
var react$1 = require('react');
var unified = require('@amplitude/unified');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var axios__default = /*#__PURE__*/_interopDefault(axios);

// recce-source/js/src/lib/api/cacheKeys.ts
var cacheKeys = {
  rowCount: (model) => ["row_count", model],
  lineage: () => ["lineage"],
  checks: () => ["checks", "list"],
  check: (checkId) => ["checks", checkId],
  checkEvents: (checkId) => ["checks", checkId, "events"],
  runs: () => ["runs"],
  run: (runId) => ["runs", runId],
  runsAggregated: () => ["runs_aggregated"],
  flag: () => ["flag"],
  instanceInfo: () => ["instance_info"],
  user: () => ["user"]
};

// recce-source/js/src/lib/const.ts
var apiUrl = process.env.NEXT_PUBLIC_API_URL;
apiUrl ??= typeof window !== "undefined" ? window.location.origin : "";
var PUBLIC_API_URL = apiUrl;
process.env.NEXT_PUBLIC_CLOUD_WEB_URL;

// recce-source/js/src/lib/api/axiosClient.ts
var axiosClient = axios__default.default.create({
  baseURL: PUBLIC_API_URL
});
new reactQuery.QueryClient();

// recce-source/js/src/lib/api/instanceInfo.ts
async function getRecceInstanceInfo() {
  return (await axiosClient.get(
    "/api/instance-info"
  )).data;
}

// recce-source/js/src/lib/hooks/useRecceInstanceInfo.tsx
var useRecceInstanceInfo = () => {
  return reactQuery.useQuery({
    queryKey: cacheKeys.instanceInfo(),
    queryFn: getRecceInstanceInfo
  });
};
var toaster = react.createToaster({
  placement: "bottom-end",
  pauseOnPageIdle: true
});

// recce-source/js/src/lib/hooks/useCheckToast.tsx
function useCheckToast() {
  function markedAsApprovedToast() {
    toaster.create({
      title: "Marked as approved",
      type: "success",
      duration: 2e3
    });
  }
  return {
    markedAsApprovedToast
  };
}

// recce-source/js/src/lib/hooks/useClipBoardToast.tsx
function useClipBoardToast() {
  function successToast(message) {
    toaster.create({
      description: message,
      type: "info",
      duration: 5e3,
      closable: true
    });
  }
  function failToast(title, error) {
    toaster.create({
      title,
      description: String(error),
      type: "error",
      duration: 5e3,
      closable: true
    });
  }
  return {
    successToast,
    failToast
  };
}
var LineageViewContext = react$1.createContext(void 0);
var useLineageViewContext = () => {
  return react$1.useContext(LineageViewContext);
};
function track(eventInput, eventProperties, eventOptions) {
  {
    console.log("[Tracking]", eventInput, eventProperties, eventOptions);
  }
  return unified.track(eventInput, eventProperties, eventOptions);
}
var EXPLORE_ACTION = {
  VALUE_DIFF: "value_diff"};
var EXPLORE_FORM_EVENT = {
  EXECUTE: "execute",
  CANCEL: "cancel"
};
function trackExploreActionForm(props) {
  track("[Web] explore_action_form", props);
}
function useValueDiffAlertDialog() {
  const { open, onOpen, onClose } = react.useDisclosure();
  const [nodeCount, setNodeCount] = react$1.useState(0);
  const [resolvePromise, setResolvePromise] = react$1.useState();
  const cancelRef = react$1.useRef(null);
  const confirm = react$1.useCallback(
    (nodeCount2) => {
      setNodeCount(nodeCount2);
      return new Promise((resolve) => {
        setResolvePromise(() => resolve);
        onOpen();
      });
    },
    [onOpen]
  );
  const handleConfirm = () => {
    trackExploreActionForm({
      action: EXPLORE_ACTION.VALUE_DIFF,
      event: EXPLORE_FORM_EVENT.EXECUTE
    });
    resolvePromise?.(true);
    onClose();
  };
  const handleCancel = () => {
    trackExploreActionForm({
      action: EXPLORE_ACTION.VALUE_DIFF,
      event: EXPLORE_FORM_EVENT.CANCEL
    });
    resolvePromise?.(false);
    onClose();
  };
  const ValueDiffAlertDialog = /* @__PURE__ */ jsxRuntime.jsx(
    react.Dialog.Root,
    {
      size: "xl",
      open,
      role: "alertdialog",
      initialFocusEl: () => {
        return cancelRef.current;
      },
      onOpenChange: handleCancel,
      children: /* @__PURE__ */ jsxRuntime.jsxs(react.Portal, { children: [
        /* @__PURE__ */ jsxRuntime.jsx(react.Dialog.Backdrop, {}),
        /* @__PURE__ */ jsxRuntime.jsx(react.Dialog.Positioner, { children: /* @__PURE__ */ jsxRuntime.jsxs(react.Dialog.Content, { children: [
          /* @__PURE__ */ jsxRuntime.jsx(react.Dialog.Header, { fontSize: "lg", fontWeight: "bold", children: /* @__PURE__ */ jsxRuntime.jsxs(react.Dialog.Title, { children: [
            "Value Diff on ",
            nodeCount,
            " nodes"
          ] }) }),
          /* @__PURE__ */ jsxRuntime.jsx(react.Dialog.Body, { gap: "20px", as: react.Flex, direction: "column", children: /* @__PURE__ */ jsxRuntime.jsxs(react.Box, { children: [
            "Value diff will be executed on ",
            nodeCount,
            " nodes in the Lineage, which can add extra costs to your bill."
          ] }) }),
          /* @__PURE__ */ jsxRuntime.jsxs(react.Dialog.Footer, { gap: 1, children: [
            /* @__PURE__ */ jsxRuntime.jsx(
              react.Button,
              {
                ref: cancelRef,
                onClick: handleCancel,
                variant: "outline",
                colorPalette: "gray",
                children: "Cancel"
              }
            ),
            /* @__PURE__ */ jsxRuntime.jsx(react.Button, { colorPalette: "iochmara", onClick: handleConfirm, ml: 3, children: "Execute" })
          ] }),
          /* @__PURE__ */ jsxRuntime.jsx(react.Dialog.CloseTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.CloseButton, { size: "sm" }) })
        ] }) })
      ] })
    }
  );
  return { confirm, AlertDialog: ValueDiffAlertDialog };
}
var useValueDiffAlertDialog_default = useValueDiffAlertDialog;

exports.useCheckToast = useCheckToast;
exports.useClipBoardToast = useClipBoardToast;
exports.useLineageViewContext = useLineageViewContext;
exports.useRecceInstanceInfo = useRecceInstanceInfo;
exports.useValueDiffAlertDialog = useValueDiffAlertDialog_default;
//# sourceMappingURL=hooks.js.map
//# sourceMappingURL=hooks.js.map