import {
  ark
} from "./UFYZ7HLU.jsx";
import {
  useEnvironmentContext
} from "./D2Z5BEON.jsx";

// src/components/download-trigger/download-trigger.tsx
import { downloadFile } from "@zag-js/file-utils";
import { splitProps } from "solid-js";
function DownloadTrigger(props) {
  const [downloadProps, restProps] = splitProps(props, ["fileName", "data", "mimeType", "onClick"]);
  const env = useEnvironmentContext();
  const download = (data) => {
    downloadFile({ file: data, name: downloadProps.fileName, type: downloadProps.mimeType, win: env().getWindow() });
  };
  const handleClick = (e) => {
    if (typeof downloadProps.onClick === "function") {
      downloadProps.onClick(e);
    }
    if (e.defaultPrevented) return;
    if (typeof downloadProps.data === "function") {
      const maybePromise = downloadProps.data();
      if (maybePromise instanceof Promise) {
        maybePromise.then((data) => download(data));
      } else {
        download(maybePromise);
      }
    } else {
      download(downloadProps.data);
    }
  };
  return <ark.button {...restProps} type="button" onClick={handleClick} />;
}

export {
  DownloadTrigger
};
