193 lines
8.7 KiB
JavaScript
193 lines
8.7 KiB
JavaScript
import { z } from "./index.CeK6pfoJ.js";
|
|
import { f as ROUTE_API_AJOUTE_ARTICLE_PANIER, E as ENTETE_WC_NONCE } from "./api.js";
|
|
import { M as SELECTEUR_BOUTON_AJOUT_PANIER, N as SELECTEUR_SELECTEUR_QUANTITE, O as SELECTEUR_LIENS_ONGLETS, P as SELECTEUR_SECTIONS_CONTENUS, Q as SELECTEUR_PRIX_PRODUIT, R as SELECTEUR_CONTENEUR_FLECHES_DEFILEMENT, T as SELECTEUR_FLECHE_DEFILEMENT_GAUCHE, U as SELECTEUR_FLECHE_DEFILEMENT_DROITE, V as SELECTEUR_PHOTOS_PRODUIT, W as SELECTEUR_IMAGE_COLONNE_GAUCHE, X as SELECTEUR_IMAGES_COLONNE_DROITE, Y as ATTRIBUT_INDEX_IMAGE_ACTIVE, Z as ATTRIBUT_ARIA_SELECTED, k as ATTRIBUT_HIDDEN, C as ATTRIBUT_DESACTIVE, _ as ATTRIBUT_PRIX } from "./dom.js";
|
|
import { r as recupereElementOuLeve, d as recupereElementsOuLeve, R as Ra } from "./dom2.js";
|
|
import { l as leveServerError, r as reporteErreur } from "./erreurs2.js";
|
|
import { b as estHTMLSelectElement, e as estReponse500, a as estError } from "./gardes.js";
|
|
import { e as emetMessageMajBoutonPanier } from "./messages.js";
|
|
import { t as traiteReponseBackendWCSelonCodesHTTP } from "./reseau.js";
|
|
import { W as WCStoreCartAddItemArgsSchema } from "./cart-add-item.js";
|
|
import { W as WCStoreCartSchema } from "./cart.js";
|
|
import { r as recupereElementDocumentEither, a as recupereElementDansDocumentOuLeve, c as recupereElementsDocumentEither, b as recupereElementsDansDocumentOuLeve, y } from "./utils.js";
|
|
import { e as eitherParse } from "./validation.js";
|
|
import { p as pipe } from "./pipe.XPB0wEfw.js";
|
|
import { l } from "./index-0eef19ec.Bvb4qYFq.js";
|
|
import { M as Maybe } from "./Either.wHNxn7Os.js";
|
|
import "./exports.B84S-6H1.js";
|
|
import "./index.DxUTT09Y.js";
|
|
import "./messages3.js";
|
|
import "./erreurs3.js";
|
|
import "./messages2.js";
|
|
import "./cart2.js";
|
|
import "./adresses.js";
|
|
import "./cart-coupons.js";
|
|
import "./couts-livraison.js";
|
|
import "./belt_Option-91f3b350.Bf2JA1bN.js";
|
|
const ETATS_PAGE = _etats;
|
|
const deplieToutesSections = (ensembleLiensContenus) => {
|
|
ensembleLiensContenus.forEach((ensemble) => {
|
|
ensemble[0].setAttribute(ATTRIBUT_ARIA_SELECTED, "false");
|
|
ensemble[1].setAttribute(ATTRIBUT_HIDDEN, "true");
|
|
});
|
|
};
|
|
const BOUTON_AJOUT_PANIER = pipe(
|
|
recupereElementDocumentEither(SELECTEUR_BOUTON_AJOUT_PANIER),
|
|
recupereElementOuLeve
|
|
);
|
|
const SELECTEUR_VARIATION = recupereElementDocumentEither(
|
|
SELECTEUR_SELECTEUR_QUANTITE
|
|
);
|
|
const PRIX_PRODUIT = recupereElementDansDocumentOuLeve(
|
|
SELECTEUR_PRIX_PRODUIT
|
|
);
|
|
const LIENS_ONGLETS = pipe(
|
|
recupereElementsDocumentEither(SELECTEUR_LIENS_ONGLETS),
|
|
recupereElementsOuLeve
|
|
);
|
|
const SECTIONS_CONTENUS = pipe(
|
|
recupereElementsDocumentEither(SELECTEUR_SECTIONS_CONTENUS),
|
|
recupereElementsOuLeve
|
|
);
|
|
const initialiseFlechesDefilementImages = () => {
|
|
const CONTENEUR_FLECHES_DEFILEMENT = recupereElementDansDocumentOuLeve(
|
|
SELECTEUR_CONTENEUR_FLECHES_DEFILEMENT
|
|
);
|
|
const FLECHE_DEFILEMENT_GAUCHE = recupereElementDansDocumentOuLeve(
|
|
SELECTEUR_FLECHE_DEFILEMENT_GAUCHE
|
|
);
|
|
const FLECHE_DEFILEMENT_DROITE = recupereElementDansDocumentOuLeve(
|
|
SELECTEUR_FLECHE_DEFILEMENT_DROITE
|
|
);
|
|
const PHOTOS_PRODUIT = recupereElementDansDocumentOuLeve(SELECTEUR_PHOTOS_PRODUIT);
|
|
const IMAGES = Ra.flat([
|
|
recupereElementDansDocumentOuLeve(SELECTEUR_IMAGE_COLONNE_GAUCHE),
|
|
recupereElementsDansDocumentOuLeve(SELECTEUR_IMAGES_COLONNE_DROITE)
|
|
]);
|
|
const recupereIndexImageCourante = () => Number(PHOTOS_PRODUIT.getAttribute(ATTRIBUT_INDEX_IMAGE_ACTIVE));
|
|
Ra.forEachWithIndex([IMAGES.at(0), IMAGES.at(-1)], (index, image) => {
|
|
if (!image) return;
|
|
new IntersectionObserver(
|
|
Ra.forEach(
|
|
(entree) => z([entree.isIntersecting, index]).with([true, 0], () => CONTENEUR_FLECHES_DEFILEMENT.removeAttribute("data-images-presentes-debut")).with([true, 1], () => CONTENEUR_FLECHES_DEFILEMENT.removeAttribute("data-images-presentes-fin")).with([false, 0], () => CONTENEUR_FLECHES_DEFILEMENT.setAttribute("data-images-presentes-debut", "")).with([false, 1], () => CONTENEUR_FLECHES_DEFILEMENT.setAttribute("data-images-presentes-fin", "")).otherwise(() => void 0)
|
|
),
|
|
{ root: null, rootMargin: "100% 0% 100% 0%", threshold: 0.5 }
|
|
).observe(image);
|
|
Ra.forEachWithIndex(IMAGES, (index2, image2) => new IntersectionObserver(
|
|
Ra.forEach((entree) => {
|
|
if (!entree.isIntersecting) return;
|
|
PHOTOS_PRODUIT.setAttribute(ATTRIBUT_INDEX_IMAGE_ACTIVE, String(index2));
|
|
}),
|
|
{ root: null, rootMargin: "100% 0% 100% 0%", threshold: 0.5 }
|
|
).observe(image2));
|
|
FLECHE_DEFILEMENT_GAUCHE.addEventListener("click", () => IMAGES[recupereIndexImageCourante() - 1]?.scrollIntoView({
|
|
behavior: "smooth",
|
|
block: "nearest",
|
|
inline: "center"
|
|
}));
|
|
FLECHE_DEFILEMENT_DROITE.addEventListener("click", () => IMAGES[recupereIndexImageCourante() + 1]?.scrollIntoView({
|
|
behavior: "smooth",
|
|
block: "nearest",
|
|
inline: "center"
|
|
}));
|
|
});
|
|
};
|
|
const gereBoiteInformationsProduit = () => {
|
|
const onglets = /* @__PURE__ */ new Map();
|
|
LIENS_ONGLETS.forEach((lien, index) => {
|
|
const idOnglet = lien.getAttribute("id");
|
|
const sectionCorrespondante = SECTIONS_CONTENUS[index];
|
|
if (!idOnglet) throw new Error("Le lien ne dispose pas d'ID !");
|
|
if (!sectionCorrespondante) throw new Error("Le lien ne dispose pas de section correspondante !");
|
|
onglets.set(idOnglet, [lien, sectionCorrespondante]);
|
|
lien.addEventListener("click", (e) => {
|
|
e.preventDefault();
|
|
const estAncienOngletCourant = lien.getAttribute(ATTRIBUT_ARIA_SELECTED) === "true";
|
|
deplieToutesSections(pipe(onglets.values(), Array.from));
|
|
if (estAncienOngletCourant) return;
|
|
lien.setAttribute(ATTRIBUT_ARIA_SELECTED, "true");
|
|
sectionCorrespondante.removeAttribute(ATTRIBUT_HIDDEN);
|
|
});
|
|
});
|
|
SELECTEUR_VARIATION.ifRight(
|
|
(selecteur) => selecteur.addEventListener("change", (evenement) => {
|
|
const cibleSelecteur = pipe(
|
|
Maybe.fromNullable(evenement.target),
|
|
(cibleEvenement) => cibleEvenement.filter(estHTMLSelectElement)
|
|
);
|
|
pipe(
|
|
cibleSelecteur,
|
|
(element) => element.map((v) => v.validity.valid),
|
|
(validite) => validite.ifJust((v) => BOUTON_AJOUT_PANIER.toggleAttribute(ATTRIBUT_DESACTIVE, !v))
|
|
);
|
|
pipe(
|
|
cibleSelecteur,
|
|
(selecteur2) => selecteur2.chain((s) => Maybe.fromNullable(s.selectedOptions[0])),
|
|
(option) => option.chain((e) => Maybe.fromNullable(e.getAttribute(ATTRIBUT_PRIX))),
|
|
(prix) => prix.ifJust((p) => {
|
|
PRIX_PRODUIT.textContent = `${p}€`;
|
|
})
|
|
);
|
|
})
|
|
);
|
|
BOUTON_AJOUT_PANIER.addEventListener("click", (_) => ajouteProduitAuPanier());
|
|
};
|
|
const ajouteProduitAuPanier = () => {
|
|
BOUTON_AJOUT_PANIER.textContent = "Adding...";
|
|
const idProduit = SELECTEUR_VARIATION.map((selecteur) => selecteur.value).orDefault(String(ETATS_PAGE.idProduit));
|
|
const args = {
|
|
id: Number(idProduit),
|
|
quantity: 1
|
|
};
|
|
eitherParse(args, WCStoreCartAddItemArgsSchema).map((args2) => {
|
|
fetch(ROUTE_API_AJOUTE_ARTICLE_PANIER, {
|
|
body: JSON.stringify(args2),
|
|
credentials: "same-origin",
|
|
headers: {
|
|
Accept: "application/json",
|
|
"Content-Type": "application/json",
|
|
[ENTETE_WC_NONCE]: ETATS_PAGE.nonce
|
|
},
|
|
method: "POST",
|
|
mode: "same-origin",
|
|
signal: AbortSignal.timeout(5e3)
|
|
}).then(async (reponse) => {
|
|
if (estReponse500(reponse)) leveServerError("500 Server Error");
|
|
pipe(
|
|
// Récupère la Réponse
|
|
await reponse.json(),
|
|
// Traite tous les codes HTTPs possibles
|
|
(corpsReponse) => traiteReponseBackendWCSelonCodesHTTP(
|
|
corpsReponse,
|
|
WCStoreCartSchema
|
|
),
|
|
// Récupère le nombre de Produits dans la Panier
|
|
y.getUnsafe("items_count"),
|
|
// Déclenche les effets pour la mise à jour de l'IU
|
|
l.tap((nombreArticlesPanier) => {
|
|
BOUTON_AJOUT_PANIER.textContent = "Added to cart!";
|
|
emetMessageMajBoutonPanier({ quantiteProduits: nombreArticlesPanier });
|
|
setTimeout(() => {
|
|
SELECTEUR_VARIATION.ifRight((selecteur) => {
|
|
selecteur.value = selecteur.options.item(0)?.value ?? "--";
|
|
});
|
|
BOUTON_AJOUT_PANIER.toggleAttribute(ATTRIBUT_DESACTIVE, true);
|
|
BOUTON_AJOUT_PANIER.textContent = "Add to cart";
|
|
}, 3e3);
|
|
})
|
|
);
|
|
}).catch((e) => {
|
|
if (estError(e)) {
|
|
reporteErreur(e);
|
|
console.error(e);
|
|
} else {
|
|
console.error("e n'est pas une Erreur ?!", e);
|
|
}
|
|
BOUTON_AJOUT_PANIER.textContent = "Add to cart";
|
|
});
|
|
}).ifLeft((e) => console.error(e.issues));
|
|
};
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
gereBoiteInformationsProduit();
|
|
initialiseFlechesDefilementImages();
|
|
});
|
|
//# sourceMappingURL=scripts-page-produit.js.map
|