import { defineComponent as w, mergeModels as f, useModel as v, computed as B, watch as M, createBlock as V, openBlock as y, unref as e, withCtx as n, createVNode as i, withModifiers as N, renderSlot as U, createCommentVNode as I } from "vue";
import { aK as K, aH as R, X as S, ak as T, h as c, i as D, c as O, d as Y, I as $ } from "./start-CE9SawgU.js";
import "vue-i18n";
import "pinia";
import { K as j } from "./header-Bn1EKnBE.js";
import { K as F } from "./validation-BkM0nwzq.js";
import { j as H } from "./topBarRoutes-CBd5qLxn.js";
const J = /* @__PURE__ */ w({
  __name: "CreateEntityModal",
  props: /* @__PURE__ */ f({
    title: {},
    controller: {},
    rules: {},
    loading: { type: Boolean },
    hideEditOnSave: { type: Boolean },
    pluginName: {}
  }, {
    modelValue: { type: Boolean },
    modelModifiers: {},
    form: {},
    formModifiers: {}
  }),
  emits: /* @__PURE__ */ f(["save"], ["update:modelValue", "update:form"]),
  setup(d, { emit: b }) {
    const m = d, g = b, r = v(d, "modelValue"), o = v(d, "form"), k = B(() => ({
      key: { ...K, pattern: F(j) },
      active: {},
      ...m.rules
    })), { v$: s, isValid: u, keyErrors: E, markTouched: A, resetValidation: C, ...h } = R(`${m.pluginName}-create-entity`, {
      rules: k,
      form: o
    });
    function p(a) {
      g("save", o.value, a);
    }
    return M(
      r,
      (a) => {
        a && (o.value.key = "", o.value.active = !0);
      },
      { immediate: !0 }
    ), (a, l) => (y(), V(e(S), {
      modelValue: r.value,
      "onUpdate:modelValue": l[5] || (l[5] = (t) => r.value = t),
      title: a.title,
      "min-width": "600px",
      "max-width": "600px"
    }, {
      actions: n(() => [
        i(e($), {
          variant: "outlined",
          color: "primary",
          disabled: !e(u) || a.loading,
          text: a.$t("datahub-ui.dh-shared.save"),
          onClick: l[0] || (l[0] = (t) => p(!1))
        }, null, 8, ["disabled", "text"]),
        a.hideEditOnSave ? I("", !0) : (y(), V(e($), {
          key: 0,
          disabled: !e(u) || a.loading,
          color: "primary",
          text: a.$t("datahub-ui.dh-shared.saveAndEdit"),
          onClick: l[1] || (l[1] = (t) => p(!0))
        }, null, 8, ["disabled", "text"]))
      ]),
      default: n(() => [
        i(e(T), {
          readonly: a.loading,
          onSubmit: l[4] || (l[4] = N(() => {
          }, ["prevent"]))
        }, {
          default: n(() => [
            i(e(c), {
              class: "pa-0 mt-1",
              fluid: ""
            }, {
              default: n(() => [
                i(e(D), null, {
                  default: n(() => [
                    i(H, {
                      modelValue: o.value,
                      "onUpdate:modelValue": l[2] || (l[2] = (t) => o.value = t),
                      controller: a.controller,
                      "plugin-name": a.pluginName,
                      onInit: e(C),
                      onUpdated: e(A)
                    }, null, 8, ["modelValue", "controller", "plugin-name", "onInit", "onUpdated"]),
                    i(e(O), null, {
                      default: n(() => [
                        i(e(Y), {
                          modelValue: e(s).key.$model,
                          "onUpdate:modelValue": l[3] || (l[3] = (t) => e(s).key.$model = t),
                          label: a.$t("datahub-ui.dh-table.key"),
                          "error-messages": e(E)
                        }, null, 8, ["modelValue", "label", "error-messages"])
                      ]),
                      _: 1
                    }),
                    U(a.$slots, "default", {
                      v: e(s),
                      validations: h,
                      form: o.value
                    })
                  ]),
                  _: 3
                })
              ]),
              _: 3
            })
          ]),
          _: 3
        }, 8, ["readonly"])
      ]),
      _: 3
    }, 8, ["modelValue", "title"]));
  }
});
export {
  J as _
};
