@colabcommerce/elements 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,137 @@
1
+ import { jsx as t, jsxs as g } from "react/jsx-runtime";
2
+ import { createContext as Q, useState as c } from "react";
3
+ import { i as R, u as z, d as Y, S as V, l as K, b as W, k as X, g as J } from "./addressComponentsToAddress-CNK2WJ24.js";
4
+ import { d as $, a as U, Q as H, c as u, B as ee } from "./globals-C3lGVSJ0.js";
5
+ /**
6
+ * @license lucide-react v0.542.0 - ISC
7
+ *
8
+ * This source code is licensed under the ISC license.
9
+ * See the LICENSE file in the root directory of this source tree.
10
+ */
11
+ const se = [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]], te = $("check", se);
12
+ /**
13
+ * @license lucide-react v0.542.0 - ISC
14
+ *
15
+ * This source code is licensed under the ISC license.
16
+ * See the LICENSE file in the root directory of this source tree.
17
+ */
18
+ const ne = [
19
+ ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
20
+ ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
21
+ ], j = $("x", ne), oe = Q(), we = ({ product: e, children: l }) => {
22
+ const [n, d] = c(0), m = {
23
+ currentStep: n,
24
+ setCurrentStep: d,
25
+ product: e
26
+ };
27
+ return /* @__PURE__ */ t(oe.Provider, { value: m, children: l });
28
+ }, ae = Q(), ye = ({ children: e }) => {
29
+ const [l, n] = c(null), [d, m] = c(null), [_, r] = c(null), [C, N] = c(null), [k, v] = c(null), [D, x] = c(null), [L, S] = c(""), [I, o] = c(!1), [a, f] = c(!1), { coords: w, isGeolocationAvailable: y, isGeolocationEnabled: O, getPosition: B } = R({ suppressLocationOnMount: !0, onError: () => f(!1), onSuccess: () => f(!1), positionOptions: { enableHighAccuracy: !1 }, userDecisionTimeout: 5e3 }), F = {
30
+ lat: l,
31
+ lng: d,
32
+ isLoading: I,
33
+ setIsLoading: o,
34
+ locationName: L,
35
+ setLocationName: S,
36
+ setLocation: ({ lat: h, lng: p }) => {
37
+ n(h), m(p);
38
+ },
39
+ mapCenter: { lat: _, lng: C },
40
+ setMapCenter: ({ lat: h, lng: p }) => {
41
+ r(h), N(p);
42
+ },
43
+ searchCenter: { lat: k, lng: D },
44
+ setSearchCenter: ({ lat: h, lng: p }) => {
45
+ v(h), x(p);
46
+ },
47
+ loadingGeo: a,
48
+ geoCoords: w,
49
+ isGeolocationAvailable: y,
50
+ isGeolocationEnabled: O,
51
+ getPosition: B
52
+ };
53
+ return /* @__PURE__ */ t(ae.Provider, { value: F, children: e });
54
+ }, ce = "oHxQR", re = "ggY6v", ie = "B-vL7", de = "xpYRZ", le = "PD0AO", ue = "i1mIs", me = "TOu1q", he = "BYI6o", pe = "_8Athb", ge = "wpcV2", s = {
55
+ header: ce,
56
+ name: re,
57
+ address: ie,
58
+ distance: de,
59
+ selectBtn: le,
60
+ productList: ue,
61
+ productHeader: me,
62
+ productItem: he,
63
+ inStock: pe,
64
+ outOfStock: ge
65
+ }, De = ({ location: e, showProducts: l = !1 }) => {
66
+ var P, T, A;
67
+ const { t: n, i18n: d } = U(), m = d.language, _ = K(m), { products: r, searchCenter: C, setSelectedLocationId: N, selectedLocationId: k, setFocusedLocationId: v, setShowMap: D, setShowDetails: x } = z(), L = Y({ lat: (P = e == null ? void 0 : e.address) == null ? void 0 : P.latitude, lng: (T = e.address) == null ? void 0 : T.longitude }, C), S = _ === "km" ? L : X(L), I = Math.round(S * 10) / 10, o = e.retailer_location_hours.find((i) => i.day === (/* @__PURE__ */ new Date()).getDay()), a = /* @__PURE__ */ new Date();
68
+ let f = /* @__PURE__ */ new Date();
69
+ o && (f = new H(a.getUTCFullYear(), a.getMonth(), a.getDate(), o.open_at_hour, o.open_at_minute, 0, 0, o.timezone));
70
+ let w = /* @__PURE__ */ new Date();
71
+ o && (w = new H(a.getUTCFullYear(), a.getMonth(), a.getDate(), o.close_at_hour, o.close_at_minute, 0, 0, o.timezone));
72
+ const y = o && a >= f && a <= w, O = o && !y && a - f > 30 * 6e4 * -1, B = o && y && w - a < 30 * 6e4;
73
+ y ? B ? (u(s.hours, s.soon), n("store.closingSoon")) : (u(s.hours, s.open), n("store.openNow")) : O ? (u(s.hours, s.soon), n("store.openingSoon")) : (u(s.hours, s.closed), n("store.closedNow"));
74
+ const F = () => {
75
+ N(e.id);
76
+ }, h = () => {
77
+ v(e.id);
78
+ }, p = e.id === k ? u(s.wrapper, s.selected) : u(s.wrapper), q = (A = e == null ? void 0 : e.store_type) != null && A.includes("Studio") ? "studio" : "retailer", E = r == null ? void 0 : r.map((i) => {
79
+ var G;
80
+ const Z = (G = e == null ? void 0 : e.retailer_location_products) == null ? void 0 : G.some((M) => (M.sku === i.sku || M.external_id === i.external_id || M.collection_id === i.collection_id) && M.stocked);
81
+ return { ...i, isStocked: Z };
82
+ });
83
+ return /* @__PURE__ */ g("div", { className: p, onClick: h, children: [
84
+ /* @__PURE__ */ g("div", { className: s.header, children: [
85
+ /* @__PURE__ */ t("h4", { className: s.name, children: e.retailer_name }),
86
+ /* @__PURE__ */ t("div", { className: "text-end", children: /* @__PURE__ */ t(V, { type: q }) })
87
+ ] }),
88
+ /* @__PURE__ */ g("div", { className: u(s.distance), children: [
89
+ I,
90
+ " ",
91
+ _,
92
+ " ",
93
+ n("away")
94
+ ] }),
95
+ /* @__PURE__ */ t("section", { className: `${s.hoursWrapper} d-flex justify-content-between align-items-center pe-3`, children: /* @__PURE__ */ t(W, { hours: e == null ? void 0 : e.retailer_location_hours }) }),
96
+ /* @__PURE__ */ t("address", { className: u(s.address), children: /* @__PURE__ */ g("div", { children: [
97
+ e.address.street_line_one,
98
+ e.address.street_line_two && `, ${e.address.street_line_two}`,
99
+ " ",
100
+ e.address.city,
101
+ ", ",
102
+ e.address.province,
103
+ " ",
104
+ e.address.postal_code
105
+ ] }) }),
106
+ (r == null ? void 0 : r.length) > 0 && l && /* @__PURE__ */ g("div", { children: [
107
+ /* @__PURE__ */ t("div", { className: s.productHeader, children: n("quote.location.product_availability") }),
108
+ /* @__PURE__ */ t("div", { className: s.productList, children: E.map((i) => /* @__PURE__ */ g("div", { className: s.productItem, children: [
109
+ /* @__PURE__ */ t("div", { className: s.productStatus, children: i.isStocked ? /* @__PURE__ */ t(te, { className: s.inStock, size: 20 }) : /* @__PURE__ */ t(j, { className: s.outOfStock, size: 20 }) }),
110
+ /* @__PURE__ */ t("div", { className: s.productName, children: i.name })
111
+ ] }, i.name)) })
112
+ ] }),
113
+ /* @__PURE__ */ t(ee, { variant: "dark", size: "sm", onClick: F, className: `d-flex align-items-center px-3 py-2 ${s.selectBtn}`, children: n("quote.location.select_location") })
114
+ ] });
115
+ }, _e = "QMwKB", Le = "tlZ-O", Se = "NQEG7", fe = "MGV0F", b = {
116
+ wrapper: _e,
117
+ message: Le,
118
+ dismiss: Se,
119
+ cta: fe
120
+ }, xe = ({ onSelect: e, onDismiss: l }) => {
121
+ const { t: n } = U(), { locations: d, searchCenter: m, setSelectedLocationId: _, isLoading: r } = z(), { cc_company_retailer_location_id: C } = J(), [N, k] = c(!1), v = d.length > 0 ? Math.min(...d.map((S) => Y({ lat: S.address.latitude, lng: S.address.longitude }, m))) : null, D = !N && (d.length === 0 || v > 100) && !r, x = () => {
122
+ _(C);
123
+ }, L = () => {
124
+ k(!0), l && l();
125
+ };
126
+ return D ? /* @__PURE__ */ g("div", { className: b.wrapper, children: [
127
+ /* @__PURE__ */ t("button", { className: b.dismiss, onClick: L, children: /* @__PURE__ */ t(j, { size: 20 }) }),
128
+ /* @__PURE__ */ t("p", { className: b.message, children: n("form_out_of_area.message") }),
129
+ /* @__PURE__ */ t("button", { className: b.cta, onClick: x, children: n("form_out_of_area.cta") })
130
+ ] }) : null;
131
+ };
132
+ export {
133
+ xe as F,
134
+ De as L,
135
+ we as Q,
136
+ ye as a
137
+ };
@@ -0,0 +1,98 @@
1
+ import { jsxs as Z, jsx as p } from "react/jsx-runtime";
2
+ import { useState as k, useEffect as y, useCallback as x } from "react";
3
+ import { j as v, A as z, o as E, a as j, k as D, M as N } from "./globals-C3lGVSJ0.js";
4
+ import { u as I } from "./addressComponentsToAddress-CNK2WJ24.js";
5
+ const P = "lzEEu", _ = {
6
+ label: P
7
+ }, T = ({ location: t }) => {
8
+ var r, a, m, h, b;
9
+ const { setSelectedLocationId: u, selectedLocationId: L, setShowDetails: c, settings: o } = I(), i = ((r = o == null ? void 0 : o.entity) == null ? void 0 : r.store_type_icons) || [], d = (a = o == null ? void 0 : o.entity) == null ? void 0 : a.store_locator_default_store_icon, [w, l] = k(!1), e = () => {
10
+ u(t.id);
11
+ }, S = () => {
12
+ l(!0);
13
+ }, M = () => {
14
+ l(!1);
15
+ }, f = v(), g = L === t.id, C = (t == null ? void 0 : t.store_type) === "Palliser Studio", s = i == null ? void 0 : i.find((B) => B.name === t.store_type);
16
+ return s != null && s.url || (C ? f.studioSelected : f.standardSelected), /* @__PURE__ */ Z(
17
+ z,
18
+ {
19
+ onClick: e,
20
+ onMouseEnter: S,
21
+ onMouseLeave: M,
22
+ zIndex: g ? w ? 3 : 2 : w ? 1 : 0,
23
+ position: { lat: ((m = t == null ? void 0 : t.address) == null ? void 0 : m.latitude) * 1, lng: ((h = t.address) == null ? void 0 : h.longitude) * 1 },
24
+ children: [
25
+ w && /* @__PURE__ */ p("div", { className: _.label, children: t.retailer_name }),
26
+ /* @__PURE__ */ p("img", { src: ((b = s == null ? void 0 : s.icon) == null ? void 0 : b.url) || (d == null ? void 0 : d.url), width: g ? 32 : 24, className: E("markerIcon", _, "map-marker") })
27
+ ]
28
+ }
29
+ );
30
+ }, U = "wdRt8", $ = {
31
+ map: U
32
+ }, q = () => {
33
+ const {
34
+ locations: t,
35
+ selectedLocationId: u,
36
+ searchCenter: L,
37
+ mapCenter: c,
38
+ setMapCenter: o,
39
+ zoom: i,
40
+ setZoom: d
41
+ } = I(), { t: w } = j(), l = D(), [e, S] = k(null);
42
+ y(() => {
43
+ l && S(l);
44
+ }, [l, S]);
45
+ const M = x((s) => {
46
+ var r, a, m, h;
47
+ if (!e) return;
48
+ o({ lat: (r = e == null ? void 0 : e.getCenter()) == null ? void 0 : r.lat(), lng: (a = e == null ? void 0 : e.getCenter()) == null ? void 0 : a.lng() });
49
+ const n = new URLSearchParams(window.location.search);
50
+ n.set("lat", ((m = e == null ? void 0 : e.getCenter()) == null ? void 0 : m.lat()) * 1), n.set("lng", ((h = e == null ? void 0 : e.getCenter()) == null ? void 0 : h.lng()) * 1), window.history.replaceState({}, "", `?${n.toString()}`);
51
+ }, [e, o]), f = x((s) => {
52
+ if (!e) return;
53
+ d(e == null ? void 0 : e.getZoom());
54
+ const n = new URLSearchParams(window.location.search);
55
+ n.set("zoom", (e == null ? void 0 : e.getZoom()) * 1), window.history.replaceState({}, "", `?${n.toString()}`);
56
+ }, [e, d]), g = () => {
57
+ if (!e) return;
58
+ let s = 0;
59
+ if (t.forEach((r) => {
60
+ var a;
61
+ (a = e == null ? void 0 : e.getBounds()) != null && a.contains({ lat: r.address.latitude * 1, lng: r.address.longitude * 1 }) && s++;
62
+ }), s >= 2) return;
63
+ const n = new window.google.maps.LatLngBounds();
64
+ t.slice(0, 2).map((r) => {
65
+ n.extend({ lat: r.address.latitude * 1, lng: r.address.longitude * 1 });
66
+ }), n.extend(c), e.fitBounds(n, 15);
67
+ }, C = (s) => {
68
+ var r;
69
+ if (!e) return;
70
+ const n = new window.google.maps.LatLngBounds();
71
+ (r = e == null ? void 0 : e.getBounds()) != null && r.contains({ lat: s.address.latitude * 1, lng: s.address.longitude * 1 }) || (n.extend({ lat: s.address.latitude * 1, lng: s.address.longitude * 1 }), n.extend(L), e.fitBounds(n, 150));
72
+ };
73
+ return y(() => {
74
+ if (u && t.length > 0) {
75
+ const s = t.find((n) => n.id === u);
76
+ s && C(s);
77
+ } else t.length > 0 && g();
78
+ }, [u, t, e]), y(() => {
79
+ t.length > 0 && g();
80
+ }, [t]), !c.lat || !c.lng ? null : /* @__PURE__ */ p(
81
+ N,
82
+ {
83
+ className: [$.map, "cc-map-map"].join(" "),
84
+ defaultZoom: i,
85
+ defaultCenter: c,
86
+ mapId: "fb10c7a27b297863",
87
+ gestureHandling: "greedy",
88
+ disableDefaultUI: !0,
89
+ zoomControl: !0,
90
+ onDragend: M,
91
+ onZoomChanged: f,
92
+ children: t == null ? void 0 : t.map((s) => /* @__PURE__ */ p(T, { location: s }, s.id))
93
+ }
94
+ );
95
+ };
96
+ export {
97
+ q as S
98
+ };