import { defineComponent as C, ref as t, onMounted as M, onUnmounted as F, watch as x, resolveComponent as l, openBlock as i, createElementBlock as c, createBlock as I, withCtx as R, createVNode as a, createCommentVNode as z, createElementVNode as P } from "vue";
import { _ as V } from "./InventoryBindingForm.vue_vue_type_script_setup_true_lang-D8wXZyxi.js";
import { a as L, ao as S } from "./app-Bpb4394e.js";
const U = {
  key: 0,
  class: "flex justify-end gap-8 items-center"
}, E = {
  key: 1,
  class: "p-24 flex items-center justify-center gap-16"
}, D = /* @__PURE__ */ C({
  __name: "BindingsDialog",
  setup(N) {
    const p = L(), d = t(!0), s = t(new Array()), u = t(), o = S(y);
    async function y() {
      await p.readInventory(), u.value = o.onMessage("props:inventory-bindings", (e) => {
        d.value = !1, s.value = e;
      }).onMessage("props:inventory-bindings:validate", () => {
        var e;
        (e = f.value) == null || e.validateInputs();
      }), o.sendMessage("props:inventory-bindings");
    }
    function b() {
      o.sendMessage("@submit:inventory-bindings", s.value);
    }
    function _() {
      o.sendMessage("@close:inventory-bindings");
    }
    function k(e) {
      o.sendMessage("@click:pick-inventory-bindings", e);
    }
    const m = t(), r = t(!0);
    M(() => {
      v();
      const e = m.value;
      e && new ResizeObserver(() => {
        o.sendMessage("resize", e.scrollHeight);
      }).observe(e);
    }), F(() => {
      var e, n;
      (n = (e = u.value) == null ? void 0 : e.removeEventListener) == null || n.call(e);
    }), x([() => s.value], ([e]) => {
      o.sendMessage("@update:inventory-bindings", e);
    });
    function v() {
      const e = new URLSearchParams(window.location.href.split("?")[1] || "");
      console.log(v.name, e, e.has("hideButton")), r.value = e.has("hideButton");
    }
    const f = t();
    return (e, n) => {
      const g = l("FmButton"), B = l("FmForm"), h = l("FmCircularProgress");
      return i(), c("div", {
        class: "bg-white",
        ref_key: "resizeableRef",
        ref: m
      }, [
        d.value ? (i(), c("div", E, [
          a(h, { size: "md" }),
          n[2] || (n[2] = P("div", null, "Loading bindings dialog...", -1))
        ])) : (i(), I(B, {
          key: 0,
          onValidationSuccess: n[1] || (n[1] = () => r.value ? void 0 : b()),
          ref_key: "formRef",
          ref: f,
          class: "flex flex-col gap-16"
        }, {
          default: R(() => [
            a(V, {
              "model-value": s.value,
              "onUpdate:modelValue": n[0] || (n[0] = (w) => s.value = w),
              "iframe-mode": "",
              "onClick:pickInventoryBindings": k
            }, null, 8, ["model-value"]),
            r.value ? z("", !0) : (i(), c("div", U, [
              a(g, {
                type: "button",
                variant: "tertiary",
                label: "Close",
                onClick: _
              }),
              a(g, {
                type: "submit",
                label: "Submit"
              })
            ]))
          ]),
          _: 1
        }, 512))
      ], 512);
    };
  }
});
export {
  D as default
};
