(function() { "use strict"; function normalizeComponent(scriptExports, render, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) { var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports; if (render) { options.render = render; options.staticRenderFns = staticRenderFns; options._compiled = true; } { options._scopeId = "data-v-" + scopeId; } return { exports: scriptExports, options }; } const _sfc_main = { __name: "MapadoCheckButton", props: { mapadoToken: String }, setup(__props) { const { mapadoToken } = __props; const id = Vue.ref(null); const icon = Vue.ref("search"); const theme = Vue.ref(null); const text = Vue.ref("Vérifie si Mapado contient bien un événement correspondant."); setTimeout(() => { const idInput = document.querySelector(".k-field-name-mapadoid input"); id.value = idInput.value; idInput.addEventListener("input", () => { id.value = idInput.value; }); }, 100); function formatDateString(inputString) { const splitString = inputString.split(" "); const startDay = splitString[2]; const startMonth = splitString[3]; const startYear = splitString[4]; const endDay = splitString[9]; const endMonth = splitString[10]; const endYear = splitString[11]; const formattedString = `du ${startDay} ${startMonth} ${startYear} au ${endDay} ${endMonth} ${endYear}`; return formattedString; } function connect() { icon.value = "loader"; theme.value = "yellow"; const myHeaders = new Headers(); myHeaders.append("Authorization", "Bearer " + mapadoToken); const requestOptions = { method: "GET", headers: myHeaders, redirect: "follow" }; fetch( "https://ticketing.mapado.net/v1/ticketings/" + id.value + "?fields=id,title,slug,sellingDeviceSchedule", requestOptions ).then((response) => { console.log(response); if (response.status === 404) { throw new Error( "Aucun événement ne correspond à l'identifiant : " + id.value + "." ); } if (response.status === 500) { throw new Error( "Impossible de joindre le serveur Mapado. Veuillez réessayer plus tard." ); } return response.json(); }).then((result) => { icon.value = "check"; theme.value = "green"; const scheduleFirstKey = Object.keys(result.sellingDeviceSchedule)[0]; const schedule = formatDateString( result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase() ); console.log(result); text.value = `Événement correspondant sur Mapado : ${result.title}, ${schedule} (gérer sur Mapado.).`; }).catch((error) => { icon.value = "alert"; theme.value = "red"; text.value = "" + error + ""; console.log(error); setTimeout(() => { icon.value = "search"; theme.value = null; }, 2e3); }); } return { __sfc: true, id, icon, theme, text, formatDateString, connect }; } }; var _sfc_render = function render() { var _vm = this, _c = _vm._self._c, _setup = _vm._self._setupProxy; return _c("div", { staticClass: "k-number-field k-field k-field-name-mapadoid" }, [_c("k-button", { attrs: { "variant": "filled", "theme": _setup.theme, "icon": _setup.icon }, on: { "click": _setup.connect } }, [_vm._v("Vérifier")]), _c("footer", { staticClass: "k-field-footer" }, [_c("div", { staticClass: "k-help k-field-help k-text" }, [_c("p", { domProps: { "innerHTML": _vm._s(_setup.text) } })])])], 1); }; var _sfc_staticRenderFns = []; _sfc_render._withStripped = true; var __component__ = /* @__PURE__ */ normalizeComponent( _sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, "402405a5" ); __component__.options.__file = "/Users/adrienpayet/code/ntb/site/plugins/mapado-check/src/components/MapadoCheckButton.vue"; const MapadoCheckButton = __component__.exports; window.panel.plugin("adrienpayet/mapado-check", { fields: { "mapado-check": MapadoCheckButton } }); })();