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