import { useState as r } from "react";
import { a as h } from "../axios-f2q_J-wz.js";
const U = () => {
  const [s, a] = r(0), [c, m] = r(""), e = (o) => o.toFixed(2) + "KB";
  return { handleUploadImage: async (o, n) => {
    const u = `${o}/attachment/files`, d = new FormData();
    d.append("file", n);
    try {
      const l = await h.post(u, d, {
        headers: {
          "Content-Type": "multipart/form-data"
        },
        onUploadProgress: (t) => {
          const i = t.loaded ? Math.round(t.loaded * 100 / t.total) : 0, p = t.total ? t.total / 1024 : 0, f = t.loaded / 1024;
          m(e(f) + " / " + e(p)), a(i);
        }
      });
      return { ...n, ...l.data[0] };
    } catch {
    } finally {
      a(101);
    }
  }, loadingProgress: s, setLoadingProgress: a, counterKB: c };
};
export {
  U as default
};
