"use client";
import { useState, useRef, useCallback } from 'react';
import { CloudUpload } from 'lucide-react';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { jsxs, jsx } from 'react/jsx-runtime';

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
function cn(...inputs) {
  return twMerge(clsx(inputs));
}
function FileUploadArea(_a) {
  var _b = _a, {
    className,
    hint = "Up to 10 files, 100MB total limit",
    accept,
    multiple = true,
    disabled = false,
    onFilesSelected
  } = _b, props = __objRest(_b, [
    "className",
    "hint",
    "accept",
    "multiple",
    "disabled",
    "onFilesSelected"
  ]);
  const [isDragOver, setIsDragOver] = useState(false);
  const dragCounterRef = useRef(0);
  const inputRef = useRef(null);
  const handleFiles = useCallback(
    (fileList) => {
      if (disabled) return;
      const files = Array.from(fileList);
      queueMicrotask(() => {
        onFilesSelected == null ? void 0 : onFilesSelected(files);
      });
    },
    [disabled, onFilesSelected]
  );
  const handleDragEnter = useCallback(
    (e) => {
      e.preventDefault();
      e.stopPropagation();
      dragCounterRef.current += 1;
      if (!disabled && e.dataTransfer.types.includes("Files")) {
        setIsDragOver(true);
      }
    },
    [disabled]
  );
  const handleDragOver = useCallback((e) => {
    e.preventDefault();
    e.stopPropagation();
  }, []);
  const handleDragLeave = useCallback((e) => {
    e.preventDefault();
    e.stopPropagation();
    dragCounterRef.current = Math.max(0, dragCounterRef.current - 1);
    if (dragCounterRef.current === 0) setIsDragOver(false);
  }, []);
  const handleDrop = useCallback(
    (e) => {
      e.preventDefault();
      e.stopPropagation();
      dragCounterRef.current = 0;
      setIsDragOver(false);
      if (e.dataTransfer.files.length > 0) handleFiles(e.dataTransfer.files);
    },
    [handleFiles]
  );
  const handleInputChange = useCallback(
    (e) => {
      if (e.target.files && e.target.files.length > 0) {
        handleFiles(e.target.files);
        e.target.value = "";
      }
    },
    [handleFiles]
  );
  const handleClick = useCallback(() => {
    var _a2;
    if (!disabled) (_a2 = inputRef.current) == null ? void 0 : _a2.click();
  }, [disabled]);
  const handleKeyDown = useCallback(
    (e) => {
      var _a2;
      if (!disabled && (e.key === "Enter" || e.key === " ")) {
        e.preventDefault();
        (_a2 = inputRef.current) == null ? void 0 : _a2.click();
      }
    },
    [disabled]
  );
  return /* @__PURE__ */ jsxs(
    "div",
    __spreadProps(__spreadValues({
      "data-slot": "file-upload-area",
      role: "button",
      tabIndex: disabled ? -1 : 0,
      "aria-disabled": disabled || void 0,
      onClick: handleClick,
      onKeyDown: handleKeyDown,
      onDragEnter: handleDragEnter,
      onDragOver: handleDragOver,
      onDragLeave: handleDragLeave,
      onDrop: handleDrop,
      className: cn(
        "flex cursor-pointer flex-col items-center gap-3 rounded-lg border border-dashed px-6 py-8 transition-colors",
        "border-border bg-card",
        isDragOver && !disabled && "border-primary/50 bg-muted",
        disabled && "pointer-events-none cursor-not-allowed opacity-40",
        className
      )
    }, props), {
      children: [
        /* @__PURE__ */ jsx(
          CloudUpload,
          {
            className: cn(
              "size-10 stroke-[1.25]",
              disabled ? "text-muted-foreground/35" : "text-muted-foreground"
            ),
            "aria-hidden": true
          }
        ),
        /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-1 text-center", children: [
          /* @__PURE__ */ jsxs(
            "p",
            {
              className: cn(
                "text-sm font-medium leading-5",
                disabled ? "text-muted-foreground/40" : "text-foreground"
              ),
              children: [
                "Drop your files here, or",
                " ",
                /* @__PURE__ */ jsx(
                  "span",
                  {
                    className: cn(
                      disabled ? "text-muted-foreground/40" : "text-primary"
                    ),
                    children: "click to browse"
                  }
                )
              ]
            }
          ),
          /* @__PURE__ */ jsx(
            "p",
            {
              className: cn(
                "text-xs leading-4",
                disabled ? "text-muted-foreground/40" : "text-muted-foreground"
              ),
              children: hint
            }
          )
        ] }),
        /* @__PURE__ */ jsx(
          "input",
          {
            ref: inputRef,
            type: "file",
            multiple,
            accept,
            className: "hidden",
            onChange: handleInputChange,
            disabled
          }
        )
      ]
    })
  );
}

export { FileUploadArea };
//# sourceMappingURL=file-upload-area.js.map
//# sourceMappingURL=file-upload-area.js.map