UNPKG

react-mada-location

Version:

Composants React pour la sélection géographique à Madagascar (provinces, régions, districts).

1,299 lines (1,298 loc) 42.4 kB
import fe, { useState as f, useEffect as _ } from "react"; var I = { exports: {} }, w = {}; /** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Q; function he() { if (Q) return w; Q = 1; var t = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment"); function a(u, d, p) { var i = null; if (p !== void 0 && (i = "" + p), d.key !== void 0 && (i = "" + d.key), "key" in d) { p = {}; for (var e in d) e !== "key" && (p[e] = d[e]); } else p = d; return d = p.ref, { $$typeof: t, type: u, key: i, ref: d !== void 0 ? d : null, props: p }; } return w.Fragment = r, w.jsx = a, w.jsxs = a, w; } var P = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var K; function ge() { return K || (K = 1, process.env.NODE_ENV !== "production" && function() { function t(o) { if (o == null) return null; if (typeof o == "function") return o.$$typeof === le ? null : o.displayName || o.name || null; if (typeof o == "string") return o; switch (o) { case M: return "Fragment"; case ie: return "Profiler"; case te: return "StrictMode"; case oe: return "Suspense"; case ce: return "SuspenseList"; case de: return "Activity"; } if (typeof o == "object") switch (typeof o.tag == "number" && console.error( "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue." ), o.$$typeof) { case S: return "Portal"; case ne: return (o.displayName || "Context") + ".Provider"; case se: return (o._context.displayName || "Context") + ".Consumer"; case re: var g = o.render; return o = o.displayName, o || (o = g.displayName || g.name || "", o = o !== "" ? "ForwardRef(" + o + ")" : "ForwardRef"), o; case ae: return g = o.displayName || null, g !== null ? g : t(o.type) || "Memo"; case U: g = o._payload, o = o._init; try { return t(o(g)); } catch { } } return null; } function r(o) { return "" + o; } function a(o) { try { r(o); var g = !1; } catch { g = !0; } if (g) { g = console; var v = g.error, m = typeof Symbol == "function" && Symbol.toStringTag && o[Symbol.toStringTag] || o.constructor.name || "Object"; return v.call( g, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", m ), r(o); } } function u(o) { if (o === M) return "<>"; if (typeof o == "object" && o !== null && o.$$typeof === U) return "<...>"; try { var g = t(o); return g ? "<" + g + ">" : "<...>"; } catch { return "<...>"; } } function d() { var o = B.A; return o === null ? null : o.getOwner(); } function p() { return Error("react-stack-top-frame"); } function i(o) { if (H.call(o, "key")) { var g = Object.getOwnPropertyDescriptor(o, "key").get; if (g && g.isReactWarning) return !1; } return o.key !== void 0; } function e(o, g) { function v() { J || (J = !0, console.error( "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", g )); } v.isReactWarning = !0, Object.defineProperty(o, "key", { get: v, configurable: !0 }); } function c() { var o = t(this.type); return q[o] || (q[o] = !0, console.error( "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release." )), o = this.props.ref, o !== void 0 ? o : null; } function n(o, g, v, m, k, z, W, Y) { return v = z.ref, o = { $$typeof: y, type: o, key: g, props: z, _owner: k }, (v !== void 0 ? v : null) !== null ? Object.defineProperty(o, "ref", { enumerable: !1, get: c }) : Object.defineProperty(o, "ref", { enumerable: !1, value: null }), o._store = {}, Object.defineProperty(o._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: 0 }), Object.defineProperty(o, "_debugInfo", { configurable: !1, enumerable: !1, writable: !0, value: null }), Object.defineProperty(o, "_debugStack", { configurable: !1, enumerable: !1, writable: !0, value: W }), Object.defineProperty(o, "_debugTask", { configurable: !1, enumerable: !1, writable: !0, value: Y }), Object.freeze && (Object.freeze(o.props), Object.freeze(o)), o; } function l(o, g, v, m, k, z, W, Y) { var R = g.children; if (R !== void 0) if (m) if (pe(R)) { for (m = 0; m < R.length; m++) h(R[m]); Object.freeze && Object.freeze(R); } else console.error( "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead." ); else h(R); if (H.call(g, "key")) { R = t(o); var E = Object.keys(g).filter(function(ue) { return ue !== "key"; }); m = 0 < E.length ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}", N[R + m] || (E = 0 < E.length ? "{" + E.join(": ..., ") + ": ...}" : "{}", console.error( `A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, m, R, E, R ), N[R + m] = !0); } if (R = null, v !== void 0 && (a(v), R = "" + v), i(g) && (a(g.key), R = "" + g.key), "key" in g) { v = {}; for (var L in g) L !== "key" && (v[L] = g[L]); } else v = g; return R && e( v, typeof o == "function" ? o.displayName || o.name || "Unknown" : o ), n( o, R, z, k, d(), v, W, Y ); } function h(o) { typeof o == "object" && o !== null && o.$$typeof === y && o._store && (o._store.validated = 1); } var b = fe, y = Symbol.for("react.transitional.element"), S = Symbol.for("react.portal"), M = Symbol.for("react.fragment"), te = Symbol.for("react.strict_mode"), ie = Symbol.for("react.profiler"), se = Symbol.for("react.consumer"), ne = Symbol.for("react.context"), re = Symbol.for("react.forward_ref"), oe = Symbol.for("react.suspense"), ce = Symbol.for("react.suspense_list"), ae = Symbol.for("react.memo"), U = Symbol.for("react.lazy"), de = Symbol.for("react.activity"), le = Symbol.for("react.client.reference"), B = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, H = Object.prototype.hasOwnProperty, pe = Array.isArray, F = console.createTask ? console.createTask : function() { return null; }; b = { "react-stack-bottom-frame": function(o) { return o(); } }; var J, q = {}, X = b["react-stack-bottom-frame"].bind( b, p )(), Z = F(u(p)), N = {}; P.Fragment = M, P.jsx = function(o, g, v, m, k) { var z = 1e4 > B.recentlyCreatedOwnerStacks++; return l( o, g, v, !1, m, k, z ? Error("react-stack-top-frame") : X, z ? F(u(o)) : Z ); }, P.jsxs = function(o, g, v, m, k) { var z = 1e4 > B.recentlyCreatedOwnerStacks++; return l( o, g, v, !0, m, k, z ? Error("react-stack-top-frame") : X, z ? F(u(o)) : Z ); }; }()), P; } var ee; function be() { return ee || (ee = 1, process.env.NODE_ENV === "production" ? I.exports = he() : I.exports = ge()), I.exports; } var s = be(); const _e = { Analamanga: { region_id: 4, districts: [{ district: "Antananarivo-Renivohitra", zip_code: 101 }, { district: "Antananarivo-Atsimondrano", zip_code: 102 }, { district: "Antananarivo-Avaradrano", zip_code: 103 }, { district: "Ambohidratrimo", zip_code: 105 }, { district: "Andramasina", zip_code: 106 }, { district: "Anjozorobe", zip_code: 107 }, { district: "Ankazobe", zip_code: 108 }, { district: "Manjakandriana", zip_code: 116 }, { district: "Tsiroanomandidy", zip_code: 119 }] }, Vakinankaratra: { region_id: 5, districts: [{ district: "Ambatolampy", zip_code: 104 }, { district: "Antanifotsy", zip_code: 109 }, { district: "Antsirabe-I", zip_code: 110 }, { district: "Antsirabe-II", zip_code: 111 }, { district: "Betafo", zip_code: 113 }, { district: "Faratsiho", zip_code: 114 }] }, Itasy: { region_id: 3, districts: [{ district: "Arivonimamo", zip_code: 112 }, { district: "Miarinarivo", zip_code: 117 }, { district: "Soavinandriana", zip_code: 118 }] }, Bongolava: { region_id: 6, districts: [{ district: "Fenoarivo", zip_code: 115 }] } }, ve = { Diana: { region_id: 1, districts: [{ district: "Antsiranana-I", zip_code: 201 }, { district: "Antsiranana-II", zip_code: 202 }, { district: "Ambanja", zip_code: 203 }, { district: "Ambilobe", zip_code: 204 }, { district: "Nosy-Be", zip_code: 207 }] }, Sava: { region_id: 2, districts: [{ district: "Andapa", zip_code: 205 }, { district: "Antalaha", zip_code: 206 }, { district: "Sambava", zip_code: 208 }, { district: "Vohimarina", zip_code: 209 }] } }, xe = { "Haute-Matsiatra": { region_id: 15, districts: [{ district: "Fianarantsoa-I", zip_code: 301 }, { district: "Fianarantsoa-II", zip_code: 302 }, { district: "Ambalavao", zip_code: 303 }, { district: "Ambohimahasoa", zip_code: 305 }, { district: "Ikalamavony", zip_code: 314 }] }, "Amoron'i Mania": { region_id: 14, districts: [{ district: "Ambatofinandrahana", zip_code: 304 }, { district: "Ambositra", zip_code: 306 }, { district: "Fandriana", zip_code: 308 }, { district: "Manandriana", zip_code: 323 }] }, "Atsimo-Atsinanana": { region_id: 17, districts: [{ district: "Befotaka", zip_code: 307 }, { district: "Farafangana", zip_code: 309 }, { district: "Midongy-Atsimo", zip_code: 318 }, { district: "Vangaindrano", zip_code: 320 }, { district: "Vondrozo", zip_code: 322 }] }, Vatovavy: { region_id: 16, districts: [{ district: "Ifanadiana", zip_code: 312 }, { district: "Mananjary", zip_code: 317 }, { district: "Nosy-Varika", zip_code: 319 }] }, Fitovinany: { region_id: 23, districts: [{ district: "Ikongo", zip_code: 310 }, { district: "Manakara", zip_code: 316 }, { district: "Vohipeno", zip_code: 321 }] }, Ihorombe: { region_id: 18, districts: [{ district: "Iakora", zip_code: 311 }, { district: "Ihosy", zip_code: 313 }, { district: "Ivohibe", zip_code: 315 }] } }, me = { Boeny: { region_id: 8, districts: [{ district: "Mahajanga-I", zip_code: 401 }, { district: "Mahajanga-II", zip_code: 402 }, { district: "Ambato-Boeny", zip_code: 403 }, { district: "Marovoay", zip_code: 416 }, { district: "Mitsinjo", zip_code: 417 }, { district: "Soalala", zip_code: 420 }] }, Melaky: { region_id: 10, districts: [{ district: "Ambatomainty", zip_code: 404 }, { district: "Antsalova", zip_code: 406 }, { district: "Besalampy", zip_code: 410 }, { district: "Maintirano", zip_code: 413 }, { district: "Morafanobe", zip_code: 418 }] }, Sofia: { region_id: 7, districts: [{ district: "Analalava", zip_code: 405 }, { district: "Antsihihy", zip_code: 407 }, { district: "Bealanana", zip_code: 408 }, { district: "Befandriana-Avaratra", zip_code: 409 }, { district: "Mampikony", zip_code: 414 }, { district: "Mandritsara", zip_code: 415 }, { district: "Port-Bergé", zip_code: 419 }] }, Betsiboka: { region_id: 9, districts: [{ district: "Kandreho", zip_code: 411 }, { district: "Maevatanana", zip_code: 412 }, { district: "Tsaratanana", zip_code: 421 }] } }, Re = { Atsinanana: { region_id: 12, districts: [{ district: "Toamasina-I", zip_code: 501 }, { district: "Toamasina-II", zip_code: 502 }, { district: "Antanambao-Manampotsy", zip_code: 507 }, { district: "Ampasimanolotra", zip_code: 508 }, { district: "Mahanoro", zip_code: 510 }, { district: "Marolambo", zip_code: 513 }, { district: "Vatomandry", zip_code: 517 }] }, "Alaotra-Mangoro": { region_id: 11, districts: [{ district: "Ambatondrazaka", zip_code: 503 }, { district: "Amparafaravola", zip_code: 504 }, { district: "Andilamena", zip_code: 505 }, { district: "Anosibe", zip_code: 506 }, { district: "Moramanga", zip_code: 514 }] }, Analanjirofo: { region_id: 13, districts: [{ district: "Fenoarivo-Atsinanana", zip_code: 509 }, { district: "Mananara", zip_code: 511 }, { district: "Maroansetra", zip_code: 512 }, { district: "Sainte-Marie", zip_code: 515 }, { district: "Soanierana-Ivongo", zip_code: 516 }, { district: "Vavatenina", zip_code: 518 }] } }, ye = { "Atsimo-Andrefana": { region_id: 20, districts: [{ district: "Toliara-I", zip_code: 601 }, { district: "Toliara-II", zip_code: 602 }, { district: "Ampanihy", zip_code: 605 }, { district: "Ankazoabo-Atsimo", zip_code: 606 }, { district: "Benenitra", zip_code: 610 }, { district: "Beroroha", zip_code: 611 }, { district: "Betioky-Atsimo", zip_code: 612 }, { district: "Morombe", zip_code: 618 }, { district: "Sakaraha", zip_code: 620 }] }, Anosy: { region_id: 22, districts: [{ district: "Amboasary-Atsimo", zip_code: 603 }, { district: "Betroka", zip_code: 613 }, { district: "Taolanaro", zip_code: 614 }] }, Androy: { region_id: 21, districts: [{ district: "Ambovombe-Androy", zip_code: 604 }, { district: "Bekily", zip_code: 607 }, { district: "Beloha", zip_code: 609 }, { district: "Tsiombe", zip_code: 621 }] }, Menabe: { region_id: 19, districts: [{ district: "Belo-sur-Tsiribihina", zip_code: 608 }, { district: "Mahabo", zip_code: 615 }, { district: "Manja", zip_code: 616 }, { district: "Miandrivazo", zip_code: 617 }, { district: "Morondava", zip_code: 619 }] } }, A = { Antananarivo: _e, Antsiranana: ve, Fianarantsoa: xe, Mahajanga: me, Toamasina: Re, Toliara: ye }, D = () => A, j = () => { let t = []; return Object.entries(A).forEach(([r, a]) => { Object.entries(a).forEach(([u, d]) => { t.push({ province: r, region: u, region_id: d.region_id, districts: d.districts }); }); }), t; }, C = () => { let t = []; return Object.entries(A).forEach(([r, a]) => { Object.entries(a).forEach(([u, d]) => { d.districts.forEach((p) => { t.push({ province: r, region: u, district: p.district, zip_code: p.zip_code || null }); }); }); }), t; }, T = (t) => t && A[t] ? Object.entries(A[t]).map(([r, a]) => ({ region: r, region_id: a.region_id, districts: a.districts })) : [], x = (t) => { let r = []; return Object.entries(A).forEach(([a, u]) => { u[t] && u[t].districts.forEach((d) => { r.push({ province: a, region: t, district: d.district, zip_code: d.zip_code || null }); }); }), r; }, O = (t) => { let r = []; return t && A[t] && Object.entries(A[t]).forEach(([a, u]) => { u.districts.forEach((d) => { r.push({ province: t, region: a, district: d.district, zip_code: d.zip_code || null }); }); }), r; }, ze = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, getAllDistrictsInfo: C, getAllProvincesInfo: D, getAllRegionsInfo: j, getFullDistrictsByProvince: O, getFullDistrictsByRegion: x, getFullRegionsByProvince: T }, Symbol.toStringTag, { value: "Module" })), ke = ({ onSelectionChange: t }) => { const [r, a] = f([]), [u, d] = f(""); _(() => { (async () => { const e = j(); a(e); })(); }, []); const p = async (i) => { const e = i.target.value; if (d(e), e) { const c = await x(e), n = { [e]: { name: e, districts: c } }; t && t(n); } else t && t({}); }; return /* @__PURE__ */ s.jsxs("div", { style: $.wrapper, children: [ /* @__PURE__ */ s.jsx("div", { style: $.label, children: "Région" }), /* @__PURE__ */ s.jsxs("select", { value: u, onChange: p, style: $.select, children: [ /* @__PURE__ */ s.jsx("option", { value: "", children: "-- Sélectionnez une région --" }), r.map((i) => /* @__PURE__ */ s.jsx("option", { value: i.region, children: i.region }, i.region_id)) ] }) ] }); }, $ = { wrapper: { display: "flex", alignItems: "center", border: "1px solid #e5e7eb", borderRadius: "12px", overflow: "hidden", fontFamily: "Inter, sans-serif", width: "fit-content", backgroundColor: "#fff", marginBottom: "1rem" }, label: { backgroundColor: "#f3f4f6", padding: "8px 12px", color: "#374151", fontWeight: "500", borderRight: "1px solid #e5e7eb" }, select: { padding: "8px 12px", border: "none", outline: "none", fontWeight: "500", color: "#374151", backgroundColor: "transparent", cursor: "pointer", fontSize: "14px" } }, Ae = ({ onSelectionChange: t }) => { const [r, a] = f([]), [u, d] = f({}); _(() => { (async () => { const e = j(); a(e); })(); }, []); const p = async (i, e) => { if (e) { const c = await x(i); d((n) => { const l = { ...n, [i]: { name: i, districts: c } }; return t && t(l), l; }); } else d((c) => { const n = { ...c }; return delete n[i], t && t(n), n; }); }; return /* @__PURE__ */ s.jsx("div", { children: r.length > 0 ? r.map((i) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "checkbox", onChange: (e) => p(i.region, e.target.checked), checked: !!u[i.region] } ), i.region ] }) }, i.region)) : /* @__PURE__ */ s.jsx("p", { children: "Aucune région disponible." }) }); }, Ee = ({ onSelectionChange: t }) => { const [r, a] = f([]), [u, d] = f(""); _(() => { (async () => { const e = j(); a(e); })(); }, []); const p = async (i) => { if (d(i), i) { const e = await x(i), c = { [i]: { name: i, districts: e } }; t && t(c); } else t && t({}); }; return /* @__PURE__ */ s.jsx("div", { children: r.length > 0 ? /* @__PURE__ */ s.jsx("div", { children: r.map((i) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "radio", name: "region", value: i.region, checked: u === i.region, onChange: () => p(i.region) } ), i.region ] }) }, i.region_id)) }) : /* @__PURE__ */ s.jsx("p", { children: "Aucune région disponible." }) }); }, we = ({ onRegionSelected: t, renderRegions: r, renderDistricts: a }) => { const [u, d] = f([]), [p, i] = f(null), [e, c] = f([]); _(() => { (() => { const h = j(); d(h); })(); }, []); const n = async (l) => { i(l); const h = await x(l); c(h), t == null || t(l, h); }; return /* @__PURE__ */ s.jsxs(s.Fragment, { children: [ r && r(u, n), p && (a == null ? void 0 : a(p, e)) ] }); }, Pe = ({ provinces: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f(""); _(() => { (() => { const n = j().filter( (l) => t.length === 0 || t.includes(l.province) ); u(n); })(); }, [t]); const i = async (e) => { const c = e.target.value; if (p(c), c) { const n = await x(c), l = { [c]: { name: c, districts: n } }; r && r(l); } else r && r({}); }; return a.length > 0 ? /* @__PURE__ */ s.jsxs("div", { style: V.wrapper, children: [ /* @__PURE__ */ s.jsx("div", { style: V.label, children: "Région" }), /* @__PURE__ */ s.jsxs("select", { value: d, onChange: i, style: V.select, children: [ /* @__PURE__ */ s.jsx("option", { value: "", children: "-- Sélectionnez une région --" }), a.map((e) => /* @__PURE__ */ s.jsx("option", { value: e.region, children: e.region }, e.region)) ] }) ] }) : /* @__PURE__ */ s.jsx("p", { children: "Aucune région disponible pour cette/ces province(s)." }); }, V = { wrapper: { display: "flex", alignItems: "center", border: "1px solid #e5e7eb", borderRadius: "12px", overflow: "hidden", fontFamily: "Inter, sans-serif", width: "fit-content", backgroundColor: "#fff", marginBottom: "1rem" }, label: { backgroundColor: "#f3f4f6", padding: "8px 12px", color: "#374151", fontWeight: "500", borderRight: "1px solid #e5e7eb" }, select: { padding: "8px 12px", border: "none", outline: "none", fontWeight: "500", color: "#374151", backgroundColor: "transparent", cursor: "pointer", fontSize: "14px" } }, De = ({ provinces: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f({}); _(() => { (async () => { const n = j().filter( (l) => t.length === 0 || t.includes(l.province) ); u(n); })(); }, [t]); const i = async (e, c) => { if (c) { const n = await x(e); p((l) => { const h = { ...l, [e]: { name: e, districts: n } }; return r && r(h), h; }); } else p((n) => { const l = { ...n }; return delete l[e], r && r(l), l; }); }; return /* @__PURE__ */ s.jsx("div", { children: a.length > 0 ? a.map((e) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "checkbox", onChange: (c) => i(e.region, c.target.checked), checked: !!d[e.region] } ), e.region ] }) }, e.region)) : /* @__PURE__ */ s.jsx("p", { children: "Aucune région disponible pour cette/ces province(s)." }) }); }, Te = ({ provinces: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f(""); _(() => { (async () => { const n = j().filter( (l) => t.length === 0 || t.includes(l.province) ); u(n); })(); }, [t]); const i = async (e) => { p(e); const c = await x(e), n = { [e]: { name: e, districts: c } }; r && r(n); }; return /* @__PURE__ */ s.jsx("div", { children: a.length > 0 ? a.map((e) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "radio", name: "region", value: e.region, onChange: () => i(e.region), checked: d === e.region } ), e.region ] }) }, e.region)) : /* @__PURE__ */ s.jsx("p", { children: "Aucune région disponible pour cette/ces province(s)." }) }); }, Ie = ({ provinces: t = [], onRegionSelected: r, renderRegions: a, renderDistricts: u }) => { const [d, p] = f([]), [i, e] = f(null), [c, n] = f([]); _(() => { (async () => { const y = j().filter( (S) => t.length === 0 || t.includes(S.province) ); p(y); })(); }, [t]); const l = async (h) => { e(h); const b = await x(h); n(b), r && r(h, b); }; return /* @__PURE__ */ s.jsxs("div", { children: [ a && a(d, l), i && u && u(i, c) ] }); }, Ce = ({ onSelectionChange: t, renderRegionsAndDistricts: r }) => { const [a, u] = f([]), [d, p] = f(null), [i, e] = f([]); _(() => { (() => { const l = Object.entries(D()).map(([h, b]) => ({ name: h, regions: b })); u(l); })(); }, []); const c = async (n) => { const l = n.target.value; p(l); const h = await T(l), b = await Promise.all( h.map(async (y) => ({ ...y, districts: await x(y.region) })) ); e(b), t && t(l, b); }; return /* @__PURE__ */ s.jsxs("div", { style: G.wrapper, children: [ /* @__PURE__ */ s.jsx("div", { style: G.label, children: "Province" }), /* @__PURE__ */ s.jsxs("select", { value: d || "", onChange: c, style: G.select, children: [ /* @__PURE__ */ s.jsx("option", { value: "", children: "Choisissez une province" }), a.map((n) => /* @__PURE__ */ s.jsx("option", { value: n.name, children: n.name }, n.name)) ] }) ] }); }, G = { wrapper: { display: "flex", alignItems: "center", border: "1px solid #e5e7eb", borderRadius: "12px", overflow: "hidden", fontFamily: "Inter, sans-serif", width: "fit-content", backgroundColor: "#fff", marginBottom: "1rem" }, label: { backgroundColor: "#f3f4f6", padding: "8px 12px", color: "#374151", fontWeight: "500", borderRight: "1px solid #e5e7eb" }, select: { padding: "8px 12px", border: "none", outline: "none", fontWeight: "500", color: "#374151", backgroundColor: "transparent", cursor: "pointer", fontSize: "14px" } }, Oe = ({ onSelectionChange: t }) => { const [r, a] = f([]), [u, d] = f({}); _(() => { (async () => { const e = Object.entries(D()).map(([c, n]) => ({ name: c, regions: n })); a(e); })(); }, []); const p = async (i, e) => { if (e) { const c = await T(i), n = await Promise.all( c.map(async (l) => ({ ...l, districts: await x(l.region) })) ); d((l) => { const h = { ...l, [i]: { name: i, regions: n } }; return t && t(h), h; }); } else d((c) => { const n = { ...c }; return delete n[i], t && t(n), n; }); }; return /* @__PURE__ */ s.jsx("div", { children: r.length > 0 ? r.map((i) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "checkbox", onChange: (e) => p(i.name, e.target.checked), checked: !!u[i.name] } ), i.name ] }) }, i.name)) : /* @__PURE__ */ s.jsx("p", { children: "Aucune province disponible." }) }); }, Se = ({ onSelectionChange: t, renderRegionsAndDistricts: r }) => { const [a, u] = f([]), [d, p] = f(null), [i, e] = f([]); _(() => { (async () => { const l = Object.entries(D()).map(([h, b]) => ({ name: h, regions: b })); u(l); })(); }, []); const c = async (n) => { const l = n.target.value; p(l); const h = await T(l), b = await Promise.all( h.map(async (y) => ({ ...y, districts: await x(y.region) })) ); e(b), t && t(l, b); }; return /* @__PURE__ */ s.jsxs("div", { children: [ /* @__PURE__ */ s.jsx("h3", { children: "Sélectionner une province :" }), a.map((n) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "radio", name: "province", value: n.name, onChange: c, checked: d === n.name } ), n.name ] }) }, n.name)), d && r ? r(d, i) : /* @__PURE__ */ s.jsx("div", { children: i.length > 0 ? i.map((n, l) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsx("pre", { children: JSON.stringify(n.districts, null, 2) }) }, l)) : /* @__PURE__ */ s.jsx("p", { children: "Aucun district trouvé pour cette province." }) }) ] }); }, Me = ({ onProvinceSelected: t, renderProvinces: r, renderRegionsAndDistricts: a }) => { const [u, d] = f([]), [p, i] = f(null), [e, c] = f([]); _(() => { (() => { const h = Object.entries(D()).map(([b, y]) => ({ name: b, regions: y })); d(h); })(); }, []); const n = async (l) => { i(l); const h = await T(l), b = await Promise.all( h.map(async (y) => ({ ...y, districts: await x(y.region) })) ); c(b), t == null || t(l, b); }; return /* @__PURE__ */ s.jsxs(s.Fragment, { children: [ r && r(u, n), p && (a == null ? void 0 : a(p, e)) ] }); }, Be = ({ onSelectionChange: t }) => { var e; const [r, a] = f([]), [u, d] = f(""); _(() => { (() => { const n = C(); a(n); })(); }, []); const p = (c) => { const n = c.target.value; d(n); const l = r.find( (h) => h.district === n ); t && t(l); }, i = u && ((e = r.find((c) => c.district === u)) == null ? void 0 : e.zip_code); return /* @__PURE__ */ s.jsxs( "div", { style: { display: "flex", alignItems: "center", border: "1px solid #e5e7eb", borderRadius: "12px", overflow: "hidden", fontFamily: "Inter, sans-serif", width: "fit-content", backgroundColor: "#fff" }, children: [ /* @__PURE__ */ s.jsx( "div", { style: { backgroundColor: "#f3f4f6", padding: "8px 12px", color: "#374151", fontWeight: "500", borderRight: "1px solid #e5e7eb" }, children: i || "ZIP" } ), /* @__PURE__ */ s.jsxs( "select", { value: u, onChange: p, style: { padding: "8px 12px", border: "none", outline: "none", fontWeight: "500", color: "#374151", backgroundColor: "transparent", cursor: "pointer", fontSize: "14px" }, children: [ /* @__PURE__ */ s.jsx("option", { value: "", children: "-- Sélectionner un district --" }), r.map((c) => /* @__PURE__ */ s.jsx("option", { value: c.district, children: c.district }, c.district)) ] } ) ] } ); }, Fe = ({ onSelectionChange: t }) => { const [r, a] = f([]), [u, d] = f({}); _(() => { (async () => { const e = C(); a(e); })(); }, []); const p = (i, e) => { d((c) => { const n = { ...c }, l = r.find( (h) => h.district === i ); return e ? n[i] = l : delete n[i], t && t(Object.values(n)), n; }); }; return /* @__PURE__ */ s.jsx("div", { children: r.length > 0 ? r.map((i) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "checkbox", onChange: (e) => p(i.district, e.target.checked), checked: !!u[i.district] } ), i.district ] }) }, i.district)) : /* @__PURE__ */ s.jsx("p", { children: "Aucun district disponible." }) }); }, We = ({ onSelectionChange: t }) => { const [r, a] = f([]), [u, d] = f(""); _(() => { (() => { const e = C(); a(e); })(); }, []); const p = (i) => { const e = i.target.value; d(e); const c = r.find( (n) => n.district === e ); t && t(c); }; return /* @__PURE__ */ s.jsx("div", { children: r.map((i) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "radio", name: "district", value: i.district, onChange: p, checked: u === i.district } ), i.district ] }) }, i.district)) }); }, Ye = ({ onDistrictSelected: t, renderDistricts: r }) => { const [a, u] = f([]); _(() => { (async () => { const i = j(); let e = []; for (const c of i) { const n = await x(c.region); e = [...e, ...n]; } u(e); })(); }, []); const d = (p) => { t == null || t(p); }; return /* @__PURE__ */ s.jsx(s.Fragment, { children: r && r(a, d) }); }, Le = ({ regions: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f(""); _(() => { let e = []; t.forEach((c) => { const n = x(c); e = [...e, ...n]; }), u(e); }, [t]); const i = (e) => { const c = e.target.value; p(c); const n = a.find((l) => l.district === c); r && r(n || null); }; return /* @__PURE__ */ s.jsxs( "div", { style: { display: "flex", alignItems: "center", border: "1px solid #e5e7eb", borderRadius: "12px", overflow: "hidden", fontFamily: "Inter, sans-serif", width: "fit-content", backgroundColor: "#fff" }, children: [ /* @__PURE__ */ s.jsx( "div", { style: { backgroundColor: "#f3f4f6", padding: "8px 12px", color: "#374151", fontWeight: "500", borderRight: "1px solid #e5e7eb" }, children: "District" } ), /* @__PURE__ */ s.jsxs( "select", { value: d, onChange: i, style: { padding: "8px 12px", border: "none", outline: "none", fontWeight: "500", color: "#374151", backgroundColor: "transparent", cursor: "pointer", fontSize: "14px" }, children: [ /* @__PURE__ */ s.jsx("option", { value: "", children: "-- Sélectionner un district --" }), a.map((e) => /* @__PURE__ */ s.jsxs("option", { value: e.district, children: [ e.district, " (", e.province, ")" ] }, e.district)) ] } ) ] } ); }, $e = ({ regions: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f({}); _(() => { let e = []; t.forEach((c) => { const n = x(c); e = [...e, ...n]; }), u(e); }, [t]); const i = (e, c) => { p((n) => { const l = { ...n }, h = a.find( (b) => b.district === e ); return c ? l[e] = h : delete l[e], r && r(Object.values(l)), l; }); }; return /* @__PURE__ */ s.jsx("div", { children: a.length > 0 ? a.map((e) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "checkbox", onChange: (c) => i(e.district, c.target.checked), checked: !!d[e.district] } ), e.district, " (", e.province, ")" ] }) }, e.district)) : /* @__PURE__ */ s.jsx("p", { children: "Aucun district trouvé pour les régions sélectionnées." }) }); }, Ve = ({ provinces: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f(""); _(() => { (async () => { const n = j().filter( (l) => t.length === 0 || t.includes(l.province) ); u(n); })(); }, [t]); const i = async (e) => { p(e); const c = await x(e), n = { [e]: { name: e, districts: c } }; r && r(n); }; return /* @__PURE__ */ s.jsx("div", { children: a.length > 0 ? a.map((e) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "radio", name: "region", value: e.region, onChange: () => i(e.region), checked: d === e.region } ), e.region ] }) }, e.region)) : /* @__PURE__ */ s.jsx("p", { children: "Aucune région disponible pour cette/ces province(s)." }) }); }, Ge = ({ regions: t = [], children: r, onSelectionChange: a }) => { const [u, d] = f([]); return _(() => { let p = []; t.forEach((i) => { const e = x(i); p = [...p, ...e]; }), d(p); }, [t]), r({ districts: u, onSelectionChange: a }); }, Ue = ({ provinces: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f(null); _(() => { let e = []; t.forEach((c) => { const n = O(c); e = [...e, ...n]; }), u(e); }, [t]); const i = (e) => { const c = e.target.value, n = a.find((l) => l.district === c); p(n || null), r && r(n || null); }; return /* @__PURE__ */ s.jsxs("div", { style: { fontFamily: "Inter, sans-serif" }, children: [ /* @__PURE__ */ s.jsx("label", { style: { display: "block", marginBottom: "0.5rem", fontWeight: 500 }, children: "Choisissez un district :" }), /* @__PURE__ */ s.jsxs( "div", { style: { display: "flex", alignItems: "center", border: "1px solid #e5e7eb", borderRadius: "12px", overflow: "hidden", backgroundColor: "#fff", width: "fit-content" }, children: [ /* @__PURE__ */ s.jsx( "div", { style: { backgroundColor: "#f3f4f6", padding: "8px 12px", color: "#374151", fontWeight: "500", borderRight: "1px solid #e5e7eb", minWidth: "50px", textAlign: "center" }, children: (d == null ? void 0 : d.zip_code) || "ZIP" } ), /* @__PURE__ */ s.jsxs( "select", { value: (d == null ? void 0 : d.district) || "", onChange: i, style: { padding: "8px 12px", border: "none", outline: "none", fontWeight: "500", color: "#374151", backgroundColor: "transparent", cursor: "pointer", fontSize: "14px" }, children: [ /* @__PURE__ */ s.jsx("option", { value: "", children: "-- Sélectionner --" }), a.map((e) => /* @__PURE__ */ s.jsxs("option", { value: e.district, children: [ e.district, " (", e.region, ")" ] }, e.district)) ] } ) ] } ) ] }); }, He = ({ provinces: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f({}); _(() => { (async () => { const n = j().filter( (l) => t.length === 0 || t.includes(l.province) ); u(n); })(); }, [t]); const i = async (e, c) => { if (c) { const n = await x(e); p((l) => { const h = { ...l, [e]: { name: e, districts: n } }; return r && r(h), h; }); } else p((n) => { const l = { ...n }; return delete l[e], r && r(l), l; }); }; return /* @__PURE__ */ s.jsx("div", { children: a.length > 0 ? a.map((e) => /* @__PURE__ */ s.jsx("div", { children: /* @__PURE__ */ s.jsxs("label", { children: [ /* @__PURE__ */ s.jsx( "input", { type: "checkbox", onChange: (c) => i(e.region, c.target.checked), checked: !!d[e.region] } ), e.region ] }) }, e.region)) : /* @__PURE__ */ s.jsx("p", { children: "Aucune région disponible pour cette/ces province(s)." }) }); }, Je = ({ provinces: t = [], onSelectionChange: r }) => { const [a, u] = f([]), [d, p] = f(""); _(() => { let e = []; t.forEach((c) => { const n = O(c); e = [...e, ...n]; }), u(e); }, [t]); const i = (e) => { p(e); const c = a.find((n) => n.district === e); r && r(c); }; return /* @__PURE__ */ s.jsx("div", { children: a.map((e) => /* @__PURE__ */ s.jsxs("label", { style: { display: "block" }, children: [ /* @__PURE__ */ s.jsx( "input", { type: "radio", name: "district", value: e.district, checked: d === e.district, onChange: () => i(e.district) } ), e.district, " (", e.region, ")" ] }, e.district)) }); }, qe = ({ provinces: t = [], children: r, onSelectionChange: a }) => { const [u, d] = f([]); return _(() => { let p = []; t.forEach((i) => { const e = O(i); p = [...p, ...e]; }), d(p); }, [t]), r({ districts: u, onSelectionChange: a }); }; export { He as DistrictByProvinceCheckboxList, Ue as DistrictByProvinceDropdown, Je as DistrictByProvinceRadioGroup, qe as DistrictByProvinceSelectorHeadless, $e as DistrictByRegionCheckboxList, Le as DistrictByRegionDropdown, Ve as DistrictByRegionRadioGroup, Ge as DistrictByRegionSelectorHeadless, Fe as DistrictCheckboxList, Be as DistrictDropdown, We as DistrictRadioGroup, Ye as DistrictSelectorHeadless, Oe as ProvinceCheckboxList, Ce as ProvinceDropdown, Se as ProvinceRadioGroup, Me as ProvinceSelectorHeadless, De as RegionByProvinceCheckboxList, Pe as RegionByProvinceDropdown, Te as RegionByProvinceRadioGroup, Ie as RegionByProvinceSelectorHeadless, Ae as RegionCheckboxList, ke as RegionDropdown, Ee as RegionRadioGroup, we as RegionSelectorHeadless, ze as geoUtils };