import { z } from "./index.CeK6pfoJ.js"; import { c as ROUTE_API_MAJ_CLIENT } from "./api.js"; import { u as SELECTEUR_BOUTON_ACTIONS_FORMULAIRE, s as SELECTEUR_FORMULAIRE_PANIER, D as SELECTEUR_SOUS_TOTAL_LIVRAISON_COUT, E as SELECTEUR_SOUS_TOTAL_LIVRAISON_PRESTATAIRE, C as ATTRIBUT_DESACTIVE, F as ATTRIBUT_CHARGEMENT } from "./dom.js"; import { l as lanceAnimationCycleTexte } from "./animations.js"; import { S as ServerError } from "./erreurs2.js"; import { p as postBackend } from "./reseau.js"; import { W as WCStoreCartSchema } from "./cart.js"; import { W as WCStoreCartUpdateCustomerArgsSchema } from "./cart-update-customer.js"; import { a as recupereElementDansDocumentOuLeve, y } from "./utils.js"; import { e as eitherParse } from "./validation.js"; import { p as pipe } from "./pipe.XPB0wEfw.js"; import { E as EitherAsync } from "./MaybeAsync.AE1jnxuc.js"; import { M as Maybe } from "./Either.wHNxn7Os.js"; import "./exports.B84S-6H1.js"; import "./index.DxUTT09Y.js"; import "./erreurs3.js"; import "./cart2.js"; import "./adresses.js"; import "./cart-coupons.js"; import "./couts-livraison.js"; import "./dom2.js"; const ETATS_PAGE = _etats; const ELEMENTS = { BOUTON_ACTIONS_FORMULAIRE: recupereElementDansDocumentOuLeve(SELECTEUR_BOUTON_ACTIONS_FORMULAIRE), FORMULAIRE_PANIER: recupereElementDansDocumentOuLeve(SELECTEUR_FORMULAIRE_PANIER), SOUS_TOTAL_LIVRAISON_COUT: recupereElementDansDocumentOuLeve(SELECTEUR_SOUS_TOTAL_LIVRAISON_COUT), SOUS_TOTAL_LIVRAISON_PRESTATAIRE: recupereElementDansDocumentOuLeve( SELECTEUR_SOUS_TOTAL_LIVRAISON_PRESTATAIRE ) }; const initialiseBoutonActions = () => { ELEMENTS.BOUTON_ACTIONS_FORMULAIRE.addEventListener("click", (evenement) => { Maybe.fromFalsy(ELEMENTS.FORMULAIRE_PANIER.checkValidity()).ifJust(() => { evenement.preventDefault(); ELEMENTS.BOUTON_ACTIONS_FORMULAIRE.setAttribute(ATTRIBUT_DESACTIVE, ""); ELEMENTS.BOUTON_ACTIONS_FORMULAIRE.setAttribute(ATTRIBUT_CHARGEMENT, ""); const animation = lanceAnimationCycleTexte({ attribut: ATTRIBUT_CHARGEMENT, element: ELEMENTS.BOUTON_ACTIONS_FORMULAIRE, etapes: [ "Loading", "Loading.", "Loading..", "Loading..." ] }); animation.callback(); animation.interval = setInterval(animation.callback, 500); }).ifJust(() => { const donneesFormulaire = pipe( new FormData(ELEMENTS.FORMULAIRE_PANIER), (formData) => formData.entries(), (entrees) => Array.from(entrees), (tuple) => y.fromPairs(tuple) ); const argumentsFormulaire = { billing_address: { address_1: donneesFormulaire["facturation-adresse"] ?? donneesFormulaire["livraison-adresse"] ?? "", address_2: "", city: donneesFormulaire["facturation-ville"] ?? donneesFormulaire["livraison-ville"] ?? "", company: "", country: "FR", email: donneesFormulaire["facturation-email"] ?? donneesFormulaire["livraison-email"] ?? "", first_name: donneesFormulaire["facturation-prenom"] ?? donneesFormulaire["livraison-prenom"] ?? "", last_name: donneesFormulaire["facturation-nom"] ?? donneesFormulaire["livraison-nom"] ?? "", phone: donneesFormulaire["facturation-telephone"] ?? donneesFormulaire["livraison-telephone"] ?? "", postcode: donneesFormulaire["facturation-code-postal"] ?? donneesFormulaire["livraison-code-postal"] ?? "", state: donneesFormulaire["facturation-region-etat"] ?? donneesFormulaire["livraison-region-etat"] ?? "" }, shipping_address: { address_1: donneesFormulaire["livraison-adresse"] ?? "", address_2: "", city: donneesFormulaire["livraison-ville"] ?? "", company: "", country: "FR", first_name: donneesFormulaire["livraison-prenom"] ?? "", last_name: donneesFormulaire["livraison-nom"] ?? "", phone: donneesFormulaire["livraison-telephone"] ?? "", postcode: donneesFormulaire["livraison-code-postal"] ?? "", state: donneesFormulaire["livraison-region-etat"] ?? "" } }; void EitherAsync.liftEither(eitherParse(argumentsFormulaire, WCStoreCartUpdateCustomerArgsSchema)).map( (args) => postBackend({ corps: JSON.stringify(args), nonce: ETATS_PAGE.nonce, route: ROUTE_API_MAJ_CLIENT }) ).chain( (reponse) => EitherAsync(async ({ throwE }) => { const reponseSimplifiee = { body: await reponse.json(), status: reponse.status }; return z(reponseSimplifiee).with({ status: 500 }, () => throwE(new ServerError("500 Server Error"))).with({ status: 200 }, () => reponseSimplifiee.body).run(); }) ).chain((corsReponse) => EitherAsync.liftEither(eitherParse(corsReponse, WCStoreCartSchema))).ifRight((panier) => { console.debug(panier); const sousTotalLivraison = panier.totals.total_shipping === "0" ? "Free" : `${String(panier.totals.total_shipping)}€`; const prestataireLivraison = panier.shipping_rates[0]?.shipping_rates[0]?.name ?? ""; ELEMENTS.SOUS_TOTAL_LIVRAISON_COUT.textContent = sousTotalLivraison; ELEMENTS.SOUS_TOTAL_LIVRAISON_PRESTATAIRE.textContent = prestataireLivraison; sessionStorage.setItem( "shipping_rates", JSON.stringify(panier.shipping_rates[0]?.shipping_rates[0] ?? "") ); ELEMENTS.BOUTON_ACTIONS_FORMULAIRE.textContent = "Check-out"; }).ifLeft((erreur) => z(erreur).with).finally(() => { ELEMENTS.BOUTON_ACTIONS_FORMULAIRE.removeAttribute(ATTRIBUT_CHARGEMENT); ELEMENTS.BOUTON_ACTIONS_FORMULAIRE.removeAttribute(ATTRIBUT_DESACTIVE); }).run(); }); }); }; export { initialiseBoutonActions as i }; //# sourceMappingURL=scripts-page-panier-adresses.js.map