"use client"
import { Wn as toaster, Xt as EXPLORE_FORM_EVENT, Yt as EXPLORE_ACTION, kt as useApiConfig, o as shareState, rn as trackExploreActionForm } from "./state-B9yzhuKs.mjs";
import React, { createContext, useCallback, useContext, useRef, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import Stack from "@mui/material/Stack";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import MuiDialog from "@mui/material/Dialog";
import DialogActions from "@mui/material/DialogActions";
import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import IconButton from "@mui/material/IconButton";
import { IoClose } from "react-icons/io5";

//#region recce-source/js/src/lib/hooks/RecceQueryContext.tsx
const defaultSqlQuery = "select * from {{ ref(\"mymodel\") }}";
const RecceQueryContext = createContext({
	sqlQuery: defaultSqlQuery,
	setSqlQuery: () => {},
	primaryKeys: void 0,
	setPrimaryKeys: () => {},
	isCustomQueries: false,
	setCustomQueries: () => {},
	baseSqlQuery: defaultSqlQuery,
	setBaseSqlQuery: () => {}
});
function RecceQueryContextProvider({ children }) {
	const [sqlQuery, setSqlQuery] = React.useState(defaultSqlQuery);
	const [baseSqlQuery, setBaseSqlQuery] = React.useState(defaultSqlQuery);
	const [isCustomQueries, setCustomQueries] = React.useState(false);
	const [primaryKeys, setPrimaryKeys] = React.useState();
	return /* @__PURE__ */ jsx(RecceQueryContext.Provider, {
		value: {
			setSqlQuery,
			sqlQuery,
			setPrimaryKeys,
			primaryKeys,
			isCustomQueries,
			setCustomQueries,
			baseSqlQuery,
			setBaseSqlQuery
		},
		children
	});
}
const useRecceQueryContext = () => useContext(RecceQueryContext);
const RowCountStateContext = createContext({
	isNodesFetching: [],
	setIsNodesFetching: () => {}
});
function RowCountStateContextProvider({ children }) {
	const [isNodesFetching, setIsNodesFetching] = React.useState([]);
	return /* @__PURE__ */ jsx(RowCountStateContext.Provider, {
		value: {
			isNodesFetching,
			setIsNodesFetching
		},
		children
	});
}
const useRowCountStateContext = () => useContext(RowCountStateContext);

//#endregion
//#region recce-source/js/src/lib/hooks/RecceShareStateContext.tsx
const ShareState = createContext(void 0);
function RecceShareStateContextProvider({ children }) {
	const [shareUrl, setShareUrl] = useState();
	const [isLoading, setIsLoading] = useState(false);
	const [error, setError] = useState();
	const { apiClient } = useApiConfig();
	const handleShareClick = async () => {
		setIsLoading(true);
		setError(void 0);
		setShareUrl(void 0);
		try {
			const response = await shareState(apiClient);
			if (response.status !== "success") {
				setError(response.message);
				return;
			}
			setShareUrl(response.share_url);
		} catch (err) {
			setError(err.message);
		} finally {
			setIsLoading(false);
		}
	};
	return /* @__PURE__ */ jsx(ShareState.Provider, {
		value: {
			shareUrl,
			isLoading,
			error,
			handleShareClick
		},
		children
	});
}
const useRecceShareStateContext = () => {
	const context = useContext(ShareState);
	if (!context) throw new Error("useRecceShareStateContext must be used within a RecceShareStateContextProvider");
	return context;
};

//#endregion
//#region recce-source/js/src/components/lineage/useValueDiffAlertDialog.tsx
function useValueDiffAlertDialog() {
	const [open, setOpen] = useState(false);
	const [nodeCount, setNodeCount] = useState(0);
	const [resolvePromise, setResolvePromise] = useState();
	const cancelRef = useRef(null);
	const confirm = useCallback((nodeCount$1) => {
		setNodeCount(nodeCount$1);
		return new Promise((resolve) => {
			setResolvePromise(() => resolve);
			setOpen(true);
		});
	}, []);
	const handleConfirm = () => {
		trackExploreActionForm({
			action: EXPLORE_ACTION.VALUE_DIFF,
			event: EXPLORE_FORM_EVENT.EXECUTE
		});
		resolvePromise?.(true);
		setOpen(false);
	};
	const handleCancel = () => {
		trackExploreActionForm({
			action: EXPLORE_ACTION.VALUE_DIFF,
			event: EXPLORE_FORM_EVENT.CANCEL
		});
		resolvePromise?.(false);
		setOpen(false);
	};
	return {
		confirm,
		AlertDialog: /* @__PURE__ */ jsxs(MuiDialog, {
			open,
			onClose: handleCancel,
			maxWidth: "md",
			fullWidth: true,
			"aria-labelledby": "value-diff-alert-dialog-title",
			children: [
				/* @__PURE__ */ jsxs(DialogTitle, {
					id: "value-diff-alert-dialog-title",
					sx: {
						fontSize: "1.125rem",
						fontWeight: "bold"
					},
					children: [
						"Value Diff on ",
						nodeCount,
						" nodes"
					]
				}),
				/* @__PURE__ */ jsx(IconButton, {
					"aria-label": "close",
					onClick: handleCancel,
					sx: {
						position: "absolute",
						right: 8,
						top: 8,
						color: "grey.500"
					},
					children: /* @__PURE__ */ jsx(IoClose, {})
				}),
				/* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(Stack, {
					spacing: "20px",
					children: /* @__PURE__ */ jsxs(Box, { children: [
						"Value diff will be executed on ",
						nodeCount,
						" nodes in the Lineage, which can add extra costs to your bill."
					] })
				}) }),
				/* @__PURE__ */ jsxs(DialogActions, {
					sx: { gap: .5 },
					children: [/* @__PURE__ */ jsx(Button, {
						ref: cancelRef,
						onClick: handleCancel,
						variant: "outlined",
						color: "neutral",
						children: "Cancel"
					}), /* @__PURE__ */ jsx(Button, {
						color: "iochmara",
						variant: "contained",
						onClick: handleConfirm,
						sx: { ml: 1.5 },
						children: "Execute"
					})]
				})
			]
		})
	};
}
var useValueDiffAlertDialog_default = useValueDiffAlertDialog;

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

//#endregion
//#region recce-source/js/src/lib/hooks/RecceCheckContext.tsx
const RecceCheckContext = createContext({
	latestSelectedCheckId: "",
	setLatestSelectedCheckId: () => {}
});
function RecceCheckContextProvider({ children }) {
	const [selectCheckId, setSelectCheckId] = React.useState("");
	return /* @__PURE__ */ jsx(RecceCheckContext.Provider, {
		value: {
			setLatestSelectedCheckId: setSelectCheckId,
			latestSelectedCheckId: selectCheckId
		},
		children
	});
}
const useRecceCheckContext = () => useContext(RecceCheckContext);

//#endregion
export { RecceShareStateContextProvider as a, RowCountStateContextProvider as c, useRowCountStateContext as d, useValueDiffAlertDialog_default as i, defaultSqlQuery as l, useRecceCheckContext as n, useRecceShareStateContext as o, useCheckToast as r, RecceQueryContextProvider as s, RecceCheckContextProvider as t, useRecceQueryContext as u };
//# sourceMappingURL=RecceCheckContext-bXdfQLGG.mjs.map