import { g as R, p as a, b0 as U, h, m as W, n as Z, q as $, u as ee, d as te, B as T, j as l, w as ae, y as le, z as v, cX as ne, A as d, H as g, i as re, x as ie } from "./index-G5Vdjjso.js";
import { F as de } from "./Field-BKPLwnpL.js";
function ue(y, e) {
  R(e, !1);
  const f = () => ie(H, "$environmentStore", b), [b, S] = le();
  let _ = a(e, "field", 8), A = a(e, "label", 8), F = a(e, "disabled", 8, !1), p = a(e, "readonly", 8, !1), w = a(e, "compact", 8, !1), k = a(e, "validation", 8), C = a(e, "extensions", 8), m = a(e, "onChange", 8), M = a(e, "maximum", 8, void 0), V = a(e, "span", 8), B = a(e, "helpText", 8, null), I = a(e, "titleText", 8), P = a(e, "clickText", 8), q = a(e, "addText", 8), z = a(e, "type", 24, () => U.ATTACHMENTS), s = a(e, "fieldApiMapper", 24, () => ({ get: (t) => t, set: (t) => t })), D = a(e, "defaultValue", 24, () => []), r = v(), o = v();
  const { API: E, notificationStore: x, environmentStore: H } = h("sdk"), u = h("form"), N = 1e6, j = (t) => {
    x.actions.warning(`Files cannot exceed ${t / N} MB. Please try again with smaller files.`);
  }, L = (t) => {
    x.actions.warning(`Please select a maximum of ${t} files.`);
  }, X = async (t) => {
    let i = new FormData();
    for (let n = 0; n < t.length; n++)
      i.append("file", t[n]);
    try {
      let n = u?.dataSource?.tableId;
      return u?.dataSource?.type === "viewV2" && (n = u.dataSource.id), await E.uploadAttachment(n, i);
    } catch {
      return [];
    }
  }, Y = (t) => {
    const i = s().set(t.detail), n = l(o).setValue(i);
    m() && n && m()({ value: i });
  };
  W(), de(y, {
    get label() {
      return A();
    },
    get field() {
      return _();
    },
    get disabled() {
      return F();
    },
    get readonly() {
      return p();
    },
    get validation() {
      return k();
    },
    get span() {
      return V();
    },
    get helpText() {
      return B();
    },
    get type() {
      return z();
    },
    get defaultValue() {
      return D();
    },
    get fieldState() {
      return l(r);
    },
    set fieldState(t) {
      T(r, t);
    },
    get fieldApi() {
      return l(o);
    },
    set fieldApi(t) {
      T(o, t);
    },
    children: (t, i) => {
      var n = Z(), G = $(n);
      {
        var J = (c) => {
          {
            let K = g(() => (re(s()), l(r), d(() => s().get(l(r).value)))), O = g(() => (l(r), d(() => l(r).disabled || l(r).readonly))), Q = g(() => (f(), d(() => f().cloud ? j : null)));
            ne(c, {
              get value() {
                return l(K);
              },
              get disabled() {
                return l(O);
              },
              get error() {
                return l(r), d(() => l(r).error);
              },
              processFiles: X,
              get handleFileTooLarge() {
                return l(Q);
              },
              handleTooManyFiles: L,
              get maximum() {
                return M();
              },
              get extensions() {
                return C();
              },
              get compact() {
                return w();
              },
              get titleText() {
                return I();
              },
              get clickText() {
                return P();
              },
              get addText() {
                return q();
              },
              $$events: { change: Y }
            });
          }
        };
        ee(G, (c) => {
          l(r) && c(J);
        });
      }
      te(t, n);
    },
    $$slots: { default: !0 },
    $$legacy: !0
  }), ae(), S();
}
export {
  ue as default
};
