UNPKG

@konnectio/core

Version:

Konnectio Core Frontend Integration.

102 lines (101 loc) 3.4 kB
import { T as e, bt as t, l as n, n as r, u as i } from "./mitt-Dp_pykgV.js"; import { A as a, E as o, M as s, P as c, T as l, V as u, at as d, et as f, lt as p } from "./SelectField-CfD2awPl.js"; //#region src/store/giftCard.ts var m = n("giftCard", () => { let { pay: n } = a(), { display: m } = s(), { metaData: h, currencyId: g, hasError: _ } = i(o()), v = o(), y = t(f.InitialState), b = p("konnectio_name", "", void 0, { serializer: d.string }), x = p("konnectio_email", "", void 0, { serializer: d.string }), S = p("konnectio_phone", "", void 0, { serializer: d.string }), C = t(""), w = t(1), T = t(!0), E = t(""), D = t({ base64: "", type: "", name: "" }), O = t(void 0), k = t(0), A = t(!1), j = t(0), M = e(() => v.metaData.hotels[0]), N = e(() => M.value.termsOfService ? M.value.termsOfService : ""), P = e(() => y.value === f.InitialState || y.value === f.WaitingForResponse), F = e(() => y.value === f.ReadyToPay), I = e(() => y.value === f.PaymentSuccess), L = e(() => { let e = { 1: { label: r.t("giftCard.hotelType"), data: [] }, 2: { label: r.t("giftCard.restaurantType"), data: [] } }, t = h.value.hotels[0].places; return t && t.forEach((t) => { e[t.placeType].data.push(t); }), Object.fromEntries(Object.entries(e).filter(([, e]) => e.data.length > 0)); }), R = e(() => j.value !== 0), z = e(() => { let e; if (R.value) e = L.value[j.value].data[0]; else if (k.value !== 0) { let t = O.value, n = L.value[k.value].data; n.length === 1 ? e = n[0] : t !== void 0 && n.forEach((n) => { String(n.id) === String(t) && (e = n); }); } return e; }), B = e(() => !(!b.value || !x.value || !(S.value.length >= 5) || !C.value || z.value === void 0)), V = e(() => !(y.value === f.InitialState && A.value)), H = e(() => !!(y.value === f.WaitingForResponse && A.value)); async function U() { try { let e = (await l().get("/gift-card/metadata", { params: { language: u() } })).data; e.success === void 0 ? _.value = !1 : _.value = !e.success, h.value = e; } catch { m({ message: r.t("alert.error.couldntFetchMetadata"), type: "warning" }); } } async function W() { y.value = f.WaitingForResponse, A.value = !0, await l().post("/gift-card/create", { termsOfserviceURL: window.location.origin, checkoutUrl: window.location.origin, currencyID: g.value, language: u(), amount: C.value, quantity: w.value, freeText: E.value, showPrice: T.value, contactName: b.value, contactEmail: x.value, contactPhone: S.value, imageBase64: c(D.value.base64), imageName: D.value.name, imageFormat: D.value.type, placeType: z.value ? z.value.placeType : void 0, placeID: z.value ? z.value.id : void 0 }).then((e) => { y.value = f.ReadyToPay, A.value = !1, n({ callback: () => console.log("Callback!"), response: e.data }); }); } function G(e) { e && (j.value = e); } return { selectedPlace: z, moduleState: y, name: b, email: x, phone: S, value: C, remark: E, showValue: T, quantity: w, media: D, placeId: O, placeType: k, showFormPage: P, showPaymentPage: F, showConfirmationPage: I, places: L, hasFilledForm: B, hasForcedPlaceType: R, isWaitingForResponse: H, isMetadataAvailable: V, termsOfService: N, fetchMetadata: U, orderGiftCard: W, initialize: G }; }); //#endregion export { m as t };