const c = (y, e, u) => {
  if (y.length === 0) return;
  const r = u ?? document, n = y.map((d) => `[name="${d}"]`).join(","), i = r.querySelectorAll(`:scope ${n}`), s = Array.from(i).reduce((d, l) => d ? l.getBoundingClientRect().top < d.getBoundingClientRect().top ? l : d : l, null);
  if (!s) return;
  const a = s.getBoundingClientRect();
  a.top >= e && a.bottom <= window.innerHeight || (s.style.scrollMarginTop = `${e}px`, s.scrollIntoView({ behavior: "smooth", block: "start" }));
}, o = ({
  i18n: y,
  getFieldConfig: e,
  visibilityConfig: u
}) => {
  const r = (n, i) => {
    const s = u?.[n];
    if (typeof s == "string")
      return {
        visible: s !== "hidden" && i,
        includeInApiPayload: i,
        readOnly: s === "readOnly"
      };
    const [a, m] = n.split("."), d = u?.[a];
    if (d) {
      if (typeof d == "string")
        return {
          visible: d !== "hidden" && i,
          includeInApiPayload: i,
          readOnly: d === "readOnly"
        };
      if (m && typeof d == "object") {
        const l = d[m];
        if (l)
          return {
            visible: (!(a === "billingAddress" || a === "deliveryAddress") ? l !== "hidden" : !0) && i,
            includeInApiPayload: i,
            readOnly: l === "readOnly"
          };
      }
    }
    return {
      visible: i,
      includeInApiPayload: i,
      readOnly: !1
    };
  };
  return [
    {
      id: "store",
      fields: [
        {
          fieldName: "store",
          required: !0,
          visible: !0,
          includeInApiPayload: !0,
          label: "payByLink.creation.summary.fields.store"
        }
      ],
      isOptional: !1
    },
    {
      id: "payment",
      fields: [
        {
          fieldName: "linkValidity.quantity",
          required: !!e("linkValidity")?.required,
          ...r("linkValidity.quantity", !!e("linkValidity")),
          label: "payByLink.creation.summary.fields.linkValidity"
        },
        {
          fieldName: "linkValidity.durationUnit",
          required: !!e("linkValidity")?.required,
          ...r("linkValidity.durationUnit", !!e("linkValidity"))
        },
        {
          fieldName: "amount.value",
          required: !!e("amountValue")?.required,
          ...r("amount.value", !!e("amountValue")),
          label: "payByLink.creation.summary.fields.amountValue"
        },
        {
          fieldName: "amount.currency",
          required: !!e("currency")?.required,
          ...r("amount.currency", !!e("currency")),
          label: "payByLink.creation.summary.fields.currency",
          options: e("currency")?.options
        },
        {
          fieldName: "reference",
          required: !!e("merchantReference")?.required,
          ...r("reference", !!e("merchantReference")),
          label: "payByLink.creation.summary.fields.merchantReference"
        },
        {
          fieldName: "linkType",
          required: !!e("linkType")?.required,
          ...r("linkType", !!e("linkType")),
          label: "payByLink.creation.summary.fields.linkType"
        },
        {
          fieldName: "description",
          required: !!e("description")?.required,
          ...r("description", !!e("description")),
          label: "payByLink.creation.summary.fields.description"
        },
        {
          fieldName: "deliverAt",
          required: !!e("deliveryDate")?.required,
          ...r("deliverAt", !!e("deliveryDate"))
        }
      ],
      isOptional: !1
    },
    {
      id: "customer",
      fields: [
        {
          fieldName: "shopperReference",
          required: !!e("shopperReference")?.required,
          ...r("shopperReference", !!e("shopperReference")),
          label: "payByLink.creation.summary.fields.shopperReference"
        },
        {
          fieldName: "shopperName.firstName",
          required: !!e("shopperName")?.required,
          ...r("shopperName.firstName", !!e("shopperName")),
          label: "payByLink.creation.summary.fields.shopperName"
        },
        {
          fieldName: "shopperName.lastName",
          required: !!e("shopperName")?.required,
          ...r("shopperName.lastName", !!e("shopperName")),
          label: "payByLink.creation.summary.fields.shopperLastName"
        },
        {
          fieldName: "shopperEmail",
          required: !!e("emailAddress")?.required,
          ...r("shopperEmail", !!e("emailAddress")),
          label: "payByLink.creation.summary.fields.emailAddress"
        },
        {
          fieldName: "sendSuccessEmailToShopper",
          required: !!e("sendSuccessEmailToShopper")?.required,
          ...r("sendSuccessEmailToShopper", !!e("sendSuccessEmailToShopper"))
        },
        {
          fieldName: "sendLinkToShopper",
          required: !!e("sendLinkToShopper")?.required,
          ...r("sendLinkToShopper", !!e("sendLinkToShopper")),
          label: "payByLink.creation.summary.fields.emailAddress"
        },
        {
          fieldName: "telephoneNumber",
          required: !!e("phoneNumber")?.required,
          ...r("telephoneNumber", !!e("phoneNumber")),
          label: "payByLink.creation.summary.fields.phoneNumber"
        },
        {
          fieldName: "countryCode",
          required: !!e("countryCode")?.required,
          ...r("countryCode", !!e("countryCode")),
          label: "payByLink.creation.summary.fields.countryCode",
          options: e("countryCode")?.options
        },
        {
          fieldName: "deliveryAddress.street",
          required: !!e("deliveryAddress")?.required,
          ...r("deliveryAddress.street", !!e("deliveryAddress")),
          label: "payByLink.creation.summary.fields.deliveryAddress.street"
        },
        {
          fieldName: "deliveryAddress.houseNumberOrName",
          required: !!e("deliveryAddress")?.required,
          ...r("deliveryAddress.houseNumberOrName", !!e("deliveryAddress")),
          label: "payByLink.creation.summary.fields.deliveryAddress.houseNumberOrName"
        },
        {
          fieldName: "deliveryAddress.postalCode",
          required: !!e("deliveryAddress")?.required,
          ...r("deliveryAddress.postalCode", !!e("deliveryAddress")),
          label: "payByLink.creation.summary.fields.deliveryAddress.postalCode"
        },
        {
          fieldName: "deliveryAddress.city",
          required: !!e("deliveryAddress")?.required,
          ...r("deliveryAddress.city", !!e("deliveryAddress")),
          label: "payByLink.creation.summary.fields.deliveryAddress.city"
        },
        {
          fieldName: "deliveryAddress.country",
          required: !!e("deliveryAddress")?.required,
          ...r("deliveryAddress.country", !!e("deliveryAddress")),
          label: "payByLink.creation.summary.fields.deliveryAddress.country"
        },
        {
          fieldName: "billingAddress.street",
          required: !!e("billingAddress")?.required,
          ...r("billingAddress.street", !!e("billingAddress")),
          label: "payByLink.creation.summary.fields.billingAddress.street"
        },
        {
          fieldName: "billingAddress.houseNumberOrName",
          required: !!e("billingAddress")?.required,
          ...r("billingAddress.houseNumberOrName", !!e("billingAddress")),
          label: "payByLink.creation.summary.fields.billingAddress.houseNumberOrName"
        },
        {
          fieldName: "billingAddress.postalCode",
          required: !!e("billingAddress")?.required,
          ...r("billingAddress.postalCode", !!e("billingAddress")),
          label: "payByLink.creation.summary.fields.billingAddress.postalCode"
        },
        {
          fieldName: "billingAddress.city",
          required: !!e("billingAddress")?.required,
          ...r("billingAddress.city", !!e("billingAddress")),
          label: "payByLink.creation.summary.fields.billingAddress.city"
        },
        {
          fieldName: "billingAddress.country",
          required: !!e("billingAddress")?.required,
          ...r("billingAddress.country", !!e("billingAddress")),
          label: "payByLink.creation.summary.fields.billingAddress.country"
        },
        {
          fieldName: "shopperLocale",
          required: !!e("shopperLocale")?.required,
          ...r("shopperLocale", !!e("shopperLocale")),
          options: e("shopperLocale")?.options
        }
      ],
      isOptional: !1
    },
    {
      id: "summary",
      title: y.get("payByLink.creation.form.steps.customer"),
      fields: [],
      isOptional: !0
    }
  ];
};
export {
  o as getFormSteps,
  c as scrollToFirstErrorField
};
