import { o as L } from "./rolldown-runtime.js";
import { i as P, t as E } from "./vendor/react.js";
import { t as D } from "./createLucideIcon.js";
import { t as k } from "./circle-alert.js";
import { t as w } from "./FileTypeIcon.js";
import { t as $ } from "./lock.js";
import { t as b } from "./x.js";
import { t as C } from "./dist.js";
import { t as v } from "./utils.js";
import { t as I } from "./Progress.js";
var M = [["path", {
  d: "M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",
  key: "p7xjir"
}]], z = D("cloud", M), A = [
  ["path", {
    d: "M12 3v12",
    key: "1x0j5s"
  }],
  ["path", {
    d: "m17 8-5-5-5 5",
    key: "7q97r8"
  }],
  ["path", {
    d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",
    key: "ih7n3h"
  }]
], V = D("upload", A), p = /* @__PURE__ */ L(P(), 1);
function B(t, r) {
  const s = r.trim();
  if (s.startsWith(".")) return t.name.toLowerCase().endsWith(s.toLowerCase());
  if (s.includes("/*")) {
    const i = s.split("/")[0];
    return t.type.startsWith(`${i}/`);
  }
  return t.type === s;
}
function G(t, r) {
  const s = r.split(",");
  return t.filter((i) => s.some((a) => B(i, a)));
}
function W(t) {
  const r = new DataTransfer();
  for (const s of t) r.items.add(s);
  return r.files;
}
function Z({ onFilesSelected: t, accept: r, multiple: s = !0, disabled: i = !1, containerRef: a }) {
  const [o, u] = p.useState(!1), c = p.useRef(0), d = !i && t !== void 0, m = p.useCallback((l) => {
    l.preventDefault(), l.stopPropagation(), d && l.dataTransfer.types.includes("Files") && (c.current += 1, c.current === 1 && u(!0));
  }, [d]), x = p.useCallback((l) => {
    l.preventDefault(), l.stopPropagation();
  }, []), h = p.useCallback((l) => {
    l.preventDefault(), l.stopPropagation(), d && (c.current -= 1, c.current <= 0 && (c.current = 0, u(!1)));
  }, [d]), f = p.useCallback((l) => {
    if (l.preventDefault(), l.stopPropagation(), c.current = 0, u(!1), !d) return;
    let n = Array.from(l.dataTransfer.files);
    r && (n = G(n, r)), !s && n.length > 1 && (n = [n[0]]), n.length !== 0 && t(W(n));
  }, [
    d,
    r,
    s,
    t
  ]);
  p.useEffect(() => {
    const l = a?.current?.ownerDocument ?? document, n = (N) => {
      N.preventDefault(), c.current > 0 && (c.current = 0, u(!1));
    };
    return l.addEventListener("drop", n), () => {
      l.removeEventListener("drop", n);
    };
  }, [a]);
  const g = p.useCallback(() => {
    if (!d) return;
    const l = a?.current?.ownerDocument ?? document, n = l.createElement("input");
    n.type = "file", r && (n.accept = r), n.multiple = s, n.addEventListener("change", () => {
      n.files && n.files.length > 0 && t?.(n.files), n.remove();
    }), l.body.appendChild(n), n.click();
  }, [
    d,
    r,
    s,
    t,
    a
  ]);
  return {
    isDragging: o,
    dropZoneProps: {
      onDragEnter: m,
      onDragOver: x,
      onDragLeave: h,
      onDrop: f
    },
    openFilePicker: g
  };
}
var e = E(), q = C("relative flex flex-col items-center justify-center rounded-xl border border-border bg-background transition-[colors,border-color,background-color,box-shadow,transform] duration-200 ease-smooth motion-reduce:transition-none", {
  variants: { state: {
    default: "border-border",
    hover: "border-primary bg-primary/5 shadow-[0_0_0_3px_var(--primary)/0.1] scale-[1.01] motion-reduce:scale-100",
    disabled: "opacity-50 cursor-not-allowed"
  } },
  defaultVariants: { state: "default" }
}), F = (0, p.forwardRef)(({ className: t, clickText: r = "Click to upload", dragText: s = "or drag and drop", supportingText: i = "SVG, PNG, JPG or GIF (max. 800x400px)", disabled: a = !1, onFilesSelected: o, accept: u, multiple: c = !0, ...d }, m) => {
  const { isDragging: x, dropZoneProps: h, openFilePicker: f } = Z({
    onFilesSelected: o,
    accept: u,
    multiple: c,
    disabled: a
  });
  return /* @__PURE__ */ (0, e.jsx)("div", {
    ref: m,
    className: v(q({ state: a ? "disabled" : x ? "hover" : "default" }), "group/upload cursor-pointer px-6 py-4", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", t),
    ...h,
    onClick: () => f(),
    role: "button",
    tabIndex: a ? -1 : 0,
    onKeyDown: (g) => {
      (g.key === "Enter" || g.key === " ") && (g.preventDefault(), f());
    },
    "aria-disabled": a,
    "aria-label": "Upload files by clicking or dragging and dropping",
    ...d,
    children: /* @__PURE__ */ (0, e.jsxs)("div", {
      className: "flex flex-col items-center gap-3 w-full",
      children: [/* @__PURE__ */ (0, e.jsx)("div", {
        className: v("flex size-10 items-center justify-center rounded-lg border border-border bg-card/60 transition-transform duration-200 ease-smooth motion-reduce:transition-none", x && "scale-110"),
        style: { boxShadow: "var(--shadow-button-inset)" },
        children: /* @__PURE__ */ (0, e.jsx)(V, { className: v("size-5 text-secondary-foreground transition-transform duration-200 ease-smooth motion-reduce:transition-none", x && "-translate-y-0.5") })
      }), /* @__PURE__ */ (0, e.jsxs)("div", {
        className: "flex flex-col items-center gap-1 w-full",
        children: [/* @__PURE__ */ (0, e.jsxs)("div", {
          className: "flex items-center justify-center gap-1",
          children: [/* @__PURE__ */ (0, e.jsx)("span", {
            className: "text-sm font-semibold text-secondary-foreground underline underline-offset-2 decoration-transparent transition-[text-decoration-color] duration-200 ease-smooth motion-reduce:transition-none group-hover/upload:decoration-secondary-foreground/40",
            children: r
          }), /* @__PURE__ */ (0, e.jsx)("span", {
            className: "text-sm text-muted-foreground",
            children: s
          })]
        }), /* @__PURE__ */ (0, e.jsx)("p", {
          className: "text-xs text-muted-foreground text-center",
          children: i
        })]
      })]
    })
  });
});
F.displayName = "FileUploadArea";
var y = C("relative flex items-start rounded-xl border bg-card transition-colors", {
  variants: { progressType: {
    bar: "gap-1 ps-4 pe-12 py-4 border-border",
    fill: "overflow-hidden min-h-[72px] border-border",
    compact: "border-border overflow-hidden"
  } },
  defaultVariants: { progressType: "fill" }
}), j = "inline-flex items-center justify-center rounded-full text-muted-foreground hover:text-foreground hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring transition-[colors,transform] active:scale-90 motion-reduce:active:scale-100";
function U({ size: t = 32, className: r }) {
  const s = t <= 20 ? 2.5 : 3, i = (t - s) / 2, a = 2 * Math.PI * i, o = a * 0.25;
  return /* @__PURE__ */ (0, e.jsxs)("svg", {
    width: t,
    height: t,
    viewBox: `0 0 ${t} ${t}`,
    className: v("animate-spin motion-reduce:animate-none delight-spinner-entrance", r),
    style: { animationDuration: "1s" },
    "aria-hidden": "true",
    children: [/* @__PURE__ */ (0, e.jsx)("circle", {
      cx: t / 2,
      cy: t / 2,
      r: i,
      fill: "none",
      stroke: "var(--border)",
      strokeWidth: s,
      strokeLinecap: "round"
    }), /* @__PURE__ */ (0, e.jsx)("circle", {
      cx: t / 2,
      cy: t / 2,
      r: i,
      fill: "none",
      stroke: "var(--primary)",
      strokeWidth: s,
      strokeLinecap: "round",
      strokeDasharray: `${o} ${a - o}`,
      strokeDashoffset: a * 0.25
    })]
  });
}
function T({ fileName: t, fileExtension: r, progress: s, status: i, onRemove: a, onCancel: o, onRetry: u }) {
  const c = i === "uploading", d = i === "error";
  return /* @__PURE__ */ (0, e.jsxs)("div", {
    className: "relative flex flex-col items-center justify-center gap-1.5 size-[100px] p-2",
    children: [
      c && /* @__PURE__ */ (0, e.jsx)("div", {
        className: "absolute inset-0 bg-primary/5 delight-upload-shimmer transition-[width] duration-300 ease-out",
        style: { width: `${s}%` },
        role: "progressbar",
        "aria-valuenow": s,
        "aria-valuemin": 0,
        "aria-valuemax": 100,
        "aria-label": `Uploading ${t}: ${s}%`
      }),
      /* @__PURE__ */ (0, e.jsxs)("div", {
        className: "absolute top-1 end-1 z-10",
        children: [c && o && /* @__PURE__ */ (0, e.jsx)("button", {
          type: "button",
          onClick: o,
          "aria-label": `Cancel upload of ${t}`,
          className: `size-5 bg-accent/80 ${j}`,
          children: /* @__PURE__ */ (0, e.jsx)(b, { className: "size-3" })
        }), (i === "complete" || d) && a && /* @__PURE__ */ (0, e.jsx)("button", {
          type: "button",
          onClick: a,
          "aria-label": `Remove ${t}`,
          className: `size-5 bg-accent/80 ${j}`,
          children: /* @__PURE__ */ (0, e.jsx)(b, { className: "size-3" })
        })]
      }),
      /* @__PURE__ */ (0, e.jsx)("div", {
        className: "relative",
        children: c ? /* @__PURE__ */ (0, e.jsx)(U, { size: 16 }) : d ? /* @__PURE__ */ (0, e.jsx)(k, { className: "size-4 text-destructive delight-shake" }) : /* @__PURE__ */ (0, e.jsx)(w, {
          extension: r,
          size: "sm"
        })
      }),
      /* @__PURE__ */ (0, e.jsx)("span", {
        className: "relative text-[10px] leading-tight text-muted-foreground text-center truncate max-w-[80px] px-1",
        children: t
      }),
      d && u && /* @__PURE__ */ (0, e.jsx)("button", {
        type: "button",
        onClick: u,
        className: "relative text-[10px] text-destructive underline hover:text-destructive/80 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring",
        children: "Retry"
      })
    ]
  });
}
function H({ fileName: t, fileSize: r, fileExtension: s, progress: i, status: a, onRemove: o, onCancel: u, onRetry: c, titleAddon: d, actions: m }) {
  const x = a === "uploading", h = a === "error", f = a === "complete" || i >= 100;
  return /* @__PURE__ */ (0, e.jsxs)(e.Fragment, { children: [
    x && /* @__PURE__ */ (0, e.jsx)("div", {
      className: "absolute inset-0 bg-primary/5 rounded-xl delight-upload-shimmer transition-[width] duration-300 ease-out",
      style: { width: `${i}%` },
      role: "progressbar",
      "aria-valuenow": i,
      "aria-valuemin": 0,
      "aria-valuemax": 100,
      "aria-label": `Uploading ${t}: ${i}%`
    }),
    f && /* @__PURE__ */ (0, e.jsx)("div", { className: "absolute inset-0 bg-muted delight-upload-complete animate-in fade-in-0 duration-300 motion-reduce:animate-none" }),
    /* @__PURE__ */ (0, e.jsxs)("div", {
      className: "relative flex items-center gap-3 h-[72px] w-full px-3",
      children: [
        /* @__PURE__ */ (0, e.jsx)(w, {
          extension: s,
          size: "lg",
          className: "shrink-0"
        }),
        /* @__PURE__ */ (0, e.jsxs)("div", {
          className: "flex-1 min-w-0 flex flex-col gap-0.5",
          children: [/* @__PURE__ */ (0, e.jsxs)("div", {
            className: "flex items-center gap-2 min-w-0",
            children: [/* @__PURE__ */ (0, e.jsx)("span", {
              className: "text-sm font-medium text-foreground truncate",
              children: t
            }), d]
          }), /* @__PURE__ */ (0, e.jsx)("span", {
            className: "text-xs text-muted-foreground",
            children: h ? /* @__PURE__ */ (0, e.jsxs)("span", {
              className: "text-destructive flex items-center gap-1 delight-shake",
              children: [
                /* @__PURE__ */ (0, e.jsx)(k, { className: "size-3 shrink-0" }),
                "Upload failed",
                c && /* @__PURE__ */ (0, e.jsxs)(e.Fragment, { children: [" · ", /* @__PURE__ */ (0, e.jsx)("button", {
                  type: "button",
                  onClick: c,
                  className: "underline hover:text-destructive/80 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring",
                  children: "Retry"
                })] })
              ]
            }) : x ? `${r ?? ""} · ${i}%` : r
          })]
        }),
        /* @__PURE__ */ (0, e.jsx)("div", {
          className: "shrink-0 flex items-center gap-2",
          children: m ? /* @__PURE__ */ (0, e.jsx)("span", {
            "data-slot": "actions",
            children: m
          }) : /* @__PURE__ */ (0, e.jsxs)(e.Fragment, { children: [
            x && /* @__PURE__ */ (0, e.jsxs)(e.Fragment, { children: [/* @__PURE__ */ (0, e.jsx)(U, { size: 32 }), u && /* @__PURE__ */ (0, e.jsx)("button", {
              type: "button",
              onClick: u,
              "aria-label": `Cancel upload of ${t}`,
              className: `size-6 ${j}`,
              children: /* @__PURE__ */ (0, e.jsx)(b, { className: "size-4" })
            })] }),
            (f || h) && o && /* @__PURE__ */ (0, e.jsx)("button", {
              type: "button",
              onClick: o,
              "aria-label": `Remove ${t}`,
              className: `size-6 ${j}`,
              children: /* @__PURE__ */ (0, e.jsx)(b, { className: "size-4" })
            }),
            a === "disabled" && /* @__PURE__ */ (0, e.jsx)($, {
              className: "size-4 text-muted-foreground",
              "aria-label": "File locked"
            }),
            a === "cloud" && /* @__PURE__ */ (0, e.jsx)(z, {
              className: "size-4 text-muted-foreground",
              "aria-label": "Cloud file"
            })
          ] })
        })
      ]
    })
  ] });
}
var _ = (0, p.forwardRef)(({ className: t, fileName: r, fileSize: s, fileExtension: i, progress: a = 0, status: o = "uploading", progressType: u = "fill", titleAddon: c, onRemove: d, onCancel: m, onRetry: x, actions: h, ...f }, g) => {
  const l = Math.min(100, Math.max(0, a)), n = o === "error", N = o === "complete" || l >= 100;
  return u === "compact" ? /* @__PURE__ */ (0, e.jsx)("div", {
    ref: g,
    "data-slot": "file-upload-item",
    "data-status": o,
    className: v(y({ progressType: u }), n && "border-destructive/50", t),
    ...f,
    children: /* @__PURE__ */ (0, e.jsx)(T, {
      fileName: r,
      fileExtension: i,
      progress: l,
      status: o,
      onRemove: d,
      onCancel: m,
      onRetry: x
    })
  }) : u === "fill" ? /* @__PURE__ */ (0, e.jsx)("div", {
    ref: g,
    "data-slot": "file-upload-item",
    "data-status": o,
    className: v(y({ progressType: u }), n && "border-destructive/50", t),
    ...f,
    children: /* @__PURE__ */ (0, e.jsx)(H, {
      fileName: r,
      fileSize: s,
      fileExtension: i,
      progress: l,
      status: o,
      onRemove: d,
      onCancel: m,
      onRetry: x,
      titleAddon: c,
      actions: h
    })
  }) : /* @__PURE__ */ (0, e.jsxs)("div", {
    ref: g,
    "data-slot": "file-upload-item",
    "data-status": o,
    className: v(y({ progressType: u }), n && "border-destructive/50", t),
    ...f,
    children: [/* @__PURE__ */ (0, e.jsxs)("div", {
      className: "flex flex-1 gap-3 items-start min-w-0",
      children: [/* @__PURE__ */ (0, e.jsx)(w, {
        extension: i,
        size: "md"
      }), /* @__PURE__ */ (0, e.jsxs)("div", {
        className: "flex flex-1 flex-col gap-1 min-w-0",
        children: [/* @__PURE__ */ (0, e.jsxs)("div", {
          className: "flex flex-col w-full",
          children: [/* @__PURE__ */ (0, e.jsxs)("div", {
            className: "flex items-center gap-2 min-w-0",
            children: [/* @__PURE__ */ (0, e.jsx)("p", {
              className: "text-sm font-medium text-secondary-foreground truncate",
              children: r
            }), c]
          }), /* @__PURE__ */ (0, e.jsx)("p", {
            className: "text-sm text-muted-foreground",
            children: n ? /* @__PURE__ */ (0, e.jsxs)("span", {
              className: "text-destructive flex items-center gap-1 delight-shake",
              children: [
                /* @__PURE__ */ (0, e.jsx)(k, { className: "size-3 shrink-0" }),
                "Upload failed",
                x && /* @__PURE__ */ (0, e.jsxs)(e.Fragment, { children: [" · ", /* @__PURE__ */ (0, e.jsx)("button", {
                  type: "button",
                  onClick: x,
                  className: "underline hover:text-destructive/80 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring",
                  children: "Retry"
                })] })
              ]
            }) : s
          })]
        }), o === "uploading" && !N && /* @__PURE__ */ (0, e.jsx)(I, {
          value: l,
          size: "md",
          className: "w-full"
        })]
      })]
    }), /* @__PURE__ */ (0, e.jsx)("div", {
      className: "absolute top-2 end-4 flex items-center gap-2",
      children: h ? /* @__PURE__ */ (0, e.jsx)("span", {
        "data-slot": "actions",
        children: h
      }) : /* @__PURE__ */ (0, e.jsxs)(e.Fragment, { children: [
        o === "uploading" && m && /* @__PURE__ */ (0, e.jsx)("button", {
          type: "button",
          onClick: m,
          "aria-label": `Cancel upload of ${r}`,
          className: `size-6 ${j}`,
          children: /* @__PURE__ */ (0, e.jsx)(b, { className: "size-4" })
        }),
        (N || n) && d && /* @__PURE__ */ (0, e.jsx)("button", {
          type: "button",
          onClick: d,
          "aria-label": `Remove ${r}`,
          className: `size-6 ${j}`,
          children: /* @__PURE__ */ (0, e.jsx)(b, { className: "size-4" })
        }),
        o === "disabled" && /* @__PURE__ */ (0, e.jsx)($, {
          className: "size-4 text-muted-foreground",
          "aria-label": "File locked"
        }),
        o === "cloud" && /* @__PURE__ */ (0, e.jsx)(z, {
          className: "size-4 text-muted-foreground",
          "aria-label": "Cloud file"
        })
      ] })
    })]
  });
});
_.displayName = "FileUploadItem";
var O = (0, p.forwardRef)(({ className: t, files: r = [], progressType: s = "fill", areaProps: i, onFilesSelected: a, onFileRemove: o, onFileCancel: u, ...c }, d) => /* @__PURE__ */ (0, e.jsxs)("div", {
  ref: d,
  className: v("flex flex-col gap-4 w-full", t),
  ...c,
  children: [/* @__PURE__ */ (0, e.jsx)(F, {
    onFilesSelected: a,
    ...i
  }), r.length > 0 && /* @__PURE__ */ (0, e.jsx)("div", {
    className: "flex flex-col gap-3",
    children: r.map((m, x) => /* @__PURE__ */ (0, e.jsx)(_, {
      fileName: m.name,
      fileSize: m.size,
      fileExtension: m.extension,
      progress: m.progress,
      status: m.status,
      progressType: s,
      onRemove: () => o?.(m.id),
      onCancel: () => u?.(m.id),
      className: "delight-stagger",
      style: { "--delight-delay": `${x * 60}ms` }
    }, m.id))
  })]
}));
O.displayName = "FileUpload";
export {
  _ as n,
  Z as r,
  O as t
};

//# sourceMappingURL=FileUpload.js.map