/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

const require_runtime = require('../../_virtual/_rolldown/runtime.js');
const require_settings = require('../../settings.js');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);

//#region src/components/APIKeyModal/APIKeyDownloader.tsx
/**
* Copyright IBM Corp. 2021, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const componentName = "APIKeyDownloader";
const APIKeyDownloader = (props) => {
	const { apiKey, body, fileName, fileType, linkText, downloadLinkLabel } = props;
	const [linkProps, setLinkProps] = (0, react.useState)({});
	(0, react.useEffect)(() => {
		const generateLinkProps = async () => {
			const data = fileType === "txt" ? apiKey : JSON.stringify({ apiKey });
			const blob = new Blob([data], { type: fileType === "txt" ? "text/plain" : "application/json" });
			setLinkProps({
				href: await URL.createObjectURL(blob),
				download: `${fileName || "apikey"}.${fileType}`
			});
		};
		generateLinkProps();
	}, [
		apiKey,
		fileName,
		fileType
	]);
	return /* @__PURE__ */ react.default.createElement("div", { className: `${require_settings.pkg.prefix}--apikey-modal__download-container` }, /* @__PURE__ */ react.default.createElement("p", { className: `${require_settings.pkg.prefix}--apikey-modal__messaging-text` }, body, " ", /* @__PURE__ */ react.default.createElement("a", {
		...linkProps,
		className: `${require_settings.pkg.prefix}--apikey-modal__download-link`,
		"aria-label": downloadLinkLabel ?? linkText,
		role: "button"
	}, downloadLinkLabel ?? linkText)));
};
APIKeyDownloader.displayName = componentName;
APIKeyDownloader.propTypes = {
	apiKey: prop_types.default.string.isRequired,
	body: prop_types.default.string,
	downloadLinkLabel: prop_types.default.string,
	fileName: prop_types.default.string.isRequired,
	fileType: prop_types.default.oneOf(["txt", "json"]).isRequired,
	linkText: prop_types.default.string.isRequired
};

//#endregion
exports.APIKeyDownloader = APIKeyDownloader;