import { defineComponent as h, defineAsyncComponent as g, computed as m, reactive as C, resolveComponent as E, openBlock as p, createElementBlock as _, createElementVNode as f, toDisplayString as k, Fragment as B, renderList as q, createBlock as w, resolveDynamicComponent as M, createVNode as V } from "vue";
import { j as I, U as R, n as $, E as x, i as A, p as D, k as F } from "./index-db7a2498.mjs";
import "pinia";
const T = h({
  name: "CdsAuthRegister",
  props: {
    disabled: { type: Boolean, default: !1 },
    lang: {
      type: Object,
      default: {
        authEmail: {
          title: "Регистрация",
          submit: "Зарегистрироваться"
        }
      }
    }
  },
  emits: ["update", "register"],
  components: {
    CdsButton: I,
    CdsInputText: g(() => import("./InputText-7c424012.mjs")),
    CdsInputPassword: g(() => import("./InputPassword-56b955d1.mjs"))
  },
  setup(e, { emit: t }) {
    const v = m(() => e.lang.authEmail), b = m(() => e.disabled), r = C([
      {
        data: {
          icon: R,
          validate: $,
          iconEnd: !1,
          label: "Имя",
          errorMessage: "text error Message",
          placeholder: "Ваше имя",
          type: "text"
        },
        meta: { autocomplete: "name" },
        required: !0,
        autofocus: !0,
        name: "display_name",
        value: "",
        component: "CdsInputText"
      },
      {
        data: {
          icon: x,
          validate: A,
          iconEnd: !1,
          label: "Email",
          errorMessage: "text error Message",
          placeholder: "Ваш email",
          type: "email"
        },
        meta: { autocomplete: null },
        required: !0,
        autofocus: !0,
        name: "email",
        value: "",
        component: "CdsInputText"
      },
      {
        data: {
          icon: null,
          validate: D,
          iconEnd: !1,
          label: "Пароль",
          errorMessage: "text error Message",
          placeholder: "пароль",
          type: null
        },
        meta: { autocomplete: "current-password" },
        required: !0,
        autofocus: !0,
        name: "password",
        value: "",
        component: "CdsInputPassword"
      }
    ]), l = C({
      email: { value: "", valid: !1 },
      password: { value: "", valid: !1 },
      display_name: { value: "", valid: !1 }
    }), i = m(() => {
      let o = [];
      for (let s in l)
        o = [...o, l[s].valid];
      return o.every((s) => s);
    });
    return {
      disabled: b,
      label: v,
      fields: r,
      valid: i,
      formData: l,
      updateValue: (o) => {
        const { name: s, valid: d, value: u } = o;
        if (!s)
          return;
        const c = r.find((y) => y.name === s);
        c && (c.value = u, l[c.name] = { value: u, valid: d }), console.log(d), d && t("update", { name: s, valid: d, value: u });
      },
      send: () => t("register", l)
    };
  }
}), U = { class: "cds-auth__body" }, j = ["textContent"], N = { class: "cds-auth__form" }, P = { class: "cds-auth__action" };
function z(e, t, v, b, r, l) {
  const i = E("CdsButton");
  return p(), _("div", U, [
    f("div", {
      class: "cds-auth__title",
      textContent: k(e.label.title)
    }, null, 8, j),
    f("div", N, [
      (p(!0), _(B, null, q(e.fields, (a) => (p(), w(M(a.component), {
        key: a.name,
        data: a.data,
        meta: a.meta,
        value: a.value,
        required: a.required,
        name: a.name,
        autofocus: a.autofocus,
        disabled: e.disabled,
        inline: !0,
        onFieldUpdate: t[0] || (t[0] = (n) => e.updateValue(n)),
        onFieldChange: t[1] || (t[1] = (n) => e.updateValue(n))
      }, null, 40, ["data", "meta", "value", "required", "name", "autofocus", "disabled"]))), 128))
    ]),
    f("div", P, [
      V(i, {
        onClick: e.send,
        type: "submit",
        color: "success",
        fill: !0,
        size: "large",
        label: e.label.submit,
        disabled: !e.valid || e.disabled
      }, null, 8, ["onClick", "label", "disabled"])
    ])
  ]);
}
const G = /* @__PURE__ */ F(T, [["render", z]]);
export {
  G as default
};
//# sourceMappingURL=AuthRegister-336e1d9d.mjs.map
