@pixstella/components 0.3.0 → 0.3.1
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.
- package/COPY-PASTE.md +109 -0
- package/README.md +9 -75
- package/dist/app/components/Dashboard/dashboardRegistry.cjs +1 -1
- package/dist/app/components/Dashboard/dashboardRegistry.mjs +202 -201
- package/dist/app/components/Table/DataTable.cjs +1 -1
- package/dist/app/components/Table/DataTable.mjs +46 -49
- package/dist/app/components/ai/ConfidenceSuggestions/ConfidenceSuggestions.cjs +1 -1
- package/dist/app/components/ai/ConfidenceSuggestions/ConfidenceSuggestions.mjs +53 -53
- package/dist/app/components/ai/ProposalCard/ProposalCard.cjs +1 -1
- package/dist/app/components/ai/ProposalCard/ProposalCard.mjs +227 -227
- package/dist/app/components/ai/ReviewTable/ReviewTable.cjs +1 -1
- package/dist/app/components/ai/ReviewTable/ReviewTable.mjs +81 -81
- package/dist/app/components/ai/SuggestionChecklist/SuggestionChecklist.cjs +1 -1
- package/dist/app/components/ai/SuggestionChecklist/SuggestionChecklist.mjs +15 -14
- package/dist/app/components/ui/AuthSection/AuthSection.cjs +1 -1
- package/dist/app/components/ui/AuthSection/AuthSection.mjs +19 -18
- package/dist/app/components/ui/Checkbox/Checkbox.cjs +1 -0
- package/dist/app/components/ui/Checkbox/Checkbox.css +1 -0
- package/dist/app/components/ui/Checkbox/Checkbox.mjs +87 -0
- package/dist/app/components/ui/DataGrid/DataGrid.cjs +1 -1
- package/dist/app/components/ui/DataGrid/DataGrid.mjs +196 -199
- package/dist/app/components/ui/PreviewConfirmDialog/PreviewConfirmDialog.cjs +1 -1
- package/dist/app/components/ui/PreviewConfirmDialog/PreviewConfirmDialog.mjs +47 -48
- package/dist/browser/pixstella.esm.js +70 -70
- package/dist/browser/pixstella.standalone.js +72 -72
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.mjs +2886 -2884
- package/dist/registry/files/174512e8f294ad2f +101 -0
- package/dist/registry/files/4c7e419c8caf02c3 +119 -0
- package/dist/registry/files/{f23e788832b45fc0 → 67ac8b4abe3fc564} +2 -1
- package/dist/registry/files/{e84f443f3fc3f261 → 995feaa023211faf} +4 -8
- package/dist/registry/files/{5ba71aa83263995e → a27872a7d58aeb58} +4 -5
- package/dist/registry/files/{162078d04cb26276 → df919b524be27e88} +4 -5
- package/dist/registry/index.json +1 -1
- package/dist/styles.css +3 -0
- package/package.json +3 -10
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { usePagination as
|
|
4
|
-
import { useTableSelection as
|
|
5
|
-
import
|
|
1
|
+
import { jsx as e, jsxs as n, Fragment as A } from "react/jsx-runtime";
|
|
2
|
+
import { useState as j, useMemo as T } from "react";
|
|
3
|
+
import { usePagination as z } from "./usePagination.mjs";
|
|
4
|
+
import { useTableSelection as B } from "./useTableSelection.mjs";
|
|
5
|
+
import k from "../ui/IconButton/IconButton.mjs";
|
|
6
6
|
import './DataTable.css';/* empty css */
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
7
|
+
import G from "../../icons/glyphs/ChevronLeft.mjs";
|
|
8
|
+
import $ from "../../icons/glyphs/ChevronRight.mjs";
|
|
9
|
+
import { Checkbox as P } from "../ui/Checkbox/Checkbox.mjs";
|
|
10
|
+
function D(t) {
|
|
10
11
|
return typeof t.header == "function" ? t.header() : t.header ?? "";
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function x(t) {
|
|
13
14
|
return { width: t.width, minWidth: t.minWidth, textAlign: t.align ?? "left" };
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
+
function Q({
|
|
16
17
|
rows: t,
|
|
17
18
|
columns: c,
|
|
18
19
|
getRowId: s,
|
|
@@ -20,101 +21,97 @@ function J({
|
|
|
20
21
|
activeRowId: b,
|
|
21
22
|
onActiveRowChange: _,
|
|
22
23
|
pageSize: m,
|
|
23
|
-
pageSizeOptions:
|
|
24
|
-
emptyMessage:
|
|
24
|
+
pageSizeOptions: f = [10, 25, 50],
|
|
25
|
+
emptyMessage: C = "No data",
|
|
25
26
|
className: y = ""
|
|
26
27
|
}) {
|
|
27
|
-
const d = m != null && m > 0, [
|
|
28
|
+
const d = m != null && m > 0, [u, w] = j(m ?? 10), l = z(t, d ? u : 0), p = d ? l.pageItems : t, i = B(p, s), N = typeof _ == "function", o = T(() => h ? [
|
|
28
29
|
{
|
|
29
30
|
id: "__select",
|
|
30
31
|
width: "3rem",
|
|
31
|
-
header: () => /* @__PURE__ */
|
|
32
|
-
|
|
32
|
+
header: () => /* @__PURE__ */ e(
|
|
33
|
+
P,
|
|
33
34
|
{
|
|
34
|
-
type: "checkbox",
|
|
35
35
|
className: "dt-checkbox",
|
|
36
36
|
checked: i.isAllSelected,
|
|
37
|
-
|
|
38
|
-
e && (e.indeterminate = i.isIndeterminate);
|
|
39
|
-
},
|
|
37
|
+
indeterminate: i.isIndeterminate,
|
|
40
38
|
onChange: i.toggleAll,
|
|
41
39
|
"aria-label": "Select all"
|
|
42
40
|
}
|
|
43
41
|
),
|
|
44
|
-
cell: (
|
|
45
|
-
|
|
42
|
+
cell: (a) => /* @__PURE__ */ e("div", { onClick: (r) => r.stopPropagation(), children: /* @__PURE__ */ e(
|
|
43
|
+
P,
|
|
46
44
|
{
|
|
47
|
-
type: "checkbox",
|
|
48
45
|
className: "dt-checkbox",
|
|
49
|
-
checked: i.isSelected(s(
|
|
50
|
-
onChange: () => i.toggleRow(s(
|
|
46
|
+
checked: i.isSelected(s(a)),
|
|
47
|
+
onChange: () => i.toggleRow(s(a)),
|
|
51
48
|
"aria-label": "Select row"
|
|
52
49
|
}
|
|
53
50
|
) })
|
|
54
51
|
},
|
|
55
52
|
...c
|
|
56
|
-
] : c, [h, c, i, s]),
|
|
57
|
-
N && _(b ===
|
|
53
|
+
] : c, [h, c, i, s]), S = (a) => {
|
|
54
|
+
N && _(b === a ? null : a);
|
|
58
55
|
};
|
|
59
56
|
return /* @__PURE__ */ n("div", { className: `data-table${d ? " data-table--paginated" : ""} ${y}`.trim(), children: [
|
|
60
|
-
/* @__PURE__ */
|
|
61
|
-
/* @__PURE__ */
|
|
62
|
-
/* @__PURE__ */
|
|
63
|
-
/* @__PURE__ */
|
|
64
|
-
const r = s(
|
|
65
|
-
return /* @__PURE__ */
|
|
57
|
+
/* @__PURE__ */ e("div", { className: "data-table__scroll", children: /* @__PURE__ */ n("table", { className: "data-table__table", children: [
|
|
58
|
+
/* @__PURE__ */ e("colgroup", { children: o.map((a) => /* @__PURE__ */ e("col", { style: { width: a.width ?? a.minWidth } }, a.id)) }),
|
|
59
|
+
/* @__PURE__ */ e("thead", { className: "data-table__head", children: /* @__PURE__ */ e("tr", { children: o.map((a) => /* @__PURE__ */ e("th", { className: "data-table__th", style: x(a), children: D(a) }, a.id)) }) }),
|
|
60
|
+
/* @__PURE__ */ e("tbody", { children: p.length === 0 ? /* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { className: "data-table__empty", colSpan: o.length, children: C }) }) : p.map((a) => {
|
|
61
|
+
const r = s(a), v = b === r, W = h && i.isSelected(r);
|
|
62
|
+
return /* @__PURE__ */ e(
|
|
66
63
|
"tr",
|
|
67
64
|
{
|
|
68
65
|
className: [
|
|
69
66
|
"data-table__row",
|
|
70
67
|
N && "data-table__row--clickable",
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
W && "data-table__row--checked",
|
|
69
|
+
v && "data-table__row--active"
|
|
73
70
|
].filter(Boolean).join(" "),
|
|
74
|
-
onClick: () =>
|
|
75
|
-
"aria-selected":
|
|
76
|
-
children: o.map((g) => /* @__PURE__ */
|
|
71
|
+
onClick: () => S(r),
|
|
72
|
+
"aria-selected": v || void 0,
|
|
73
|
+
children: o.map((g) => /* @__PURE__ */ e("td", { className: "data-table__td", style: x(g), children: g.cell(a, i) }, g.id))
|
|
77
74
|
},
|
|
78
75
|
r
|
|
79
76
|
);
|
|
80
77
|
}) })
|
|
81
78
|
] }) }),
|
|
82
79
|
d && t.length > 0 && /* @__PURE__ */ n("footer", { className: "data-table__pagination", children: [
|
|
83
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ e("span", { className: "data-table__pagination-summary", children: t.length === 0 ? "No rows" : /* @__PURE__ */ n(A, { children: [
|
|
84
81
|
l.rangeStart,
|
|
85
82
|
"–",
|
|
86
83
|
l.rangeEnd,
|
|
87
84
|
" of ",
|
|
88
|
-
/* @__PURE__ */
|
|
85
|
+
/* @__PURE__ */ e("strong", { children: l.totalItems }),
|
|
89
86
|
" rows"
|
|
90
87
|
] }) }),
|
|
91
88
|
/* @__PURE__ */ n("div", { className: "data-table__pagination-actions", children: [
|
|
92
|
-
|
|
93
|
-
/* @__PURE__ */
|
|
94
|
-
/* @__PURE__ */
|
|
89
|
+
f.length > 1 && /* @__PURE__ */ n("label", { className: "data-table__page-size", children: [
|
|
90
|
+
/* @__PURE__ */ e("span", { children: "Rows per page" }),
|
|
91
|
+
/* @__PURE__ */ e(
|
|
95
92
|
"select",
|
|
96
93
|
{
|
|
97
|
-
value:
|
|
98
|
-
onChange: (
|
|
99
|
-
|
|
94
|
+
value: u,
|
|
95
|
+
onChange: (a) => {
|
|
96
|
+
w(Number(a.target.value)), l.goToPage(0);
|
|
100
97
|
},
|
|
101
|
-
children:
|
|
98
|
+
children: f.map((a) => /* @__PURE__ */ e("option", { value: a, children: a }, a))
|
|
102
99
|
}
|
|
103
100
|
)
|
|
104
101
|
] }),
|
|
105
102
|
l.totalPages > 1 && /* @__PURE__ */ n("div", { className: "data-table__pagination-nav", children: [
|
|
106
|
-
/* @__PURE__ */
|
|
103
|
+
/* @__PURE__ */ e(k, { size: "sm", tooltip: !1, icon: /* @__PURE__ */ e(G, { trim: !0, size: 14, strokeWidth: 2.5 }), label: "Previous page", className: "data-table__pagination-btn", onClick: l.goPrev, disabled: !l.canGoPrev }),
|
|
107
104
|
/* @__PURE__ */ n("span", { className: "data-table__pagination-page", children: [
|
|
108
105
|
l.pageIndex + 1,
|
|
109
106
|
" / ",
|
|
110
107
|
l.totalPages
|
|
111
108
|
] }),
|
|
112
|
-
/* @__PURE__ */
|
|
109
|
+
/* @__PURE__ */ e(k, { size: "sm", tooltip: !1, icon: /* @__PURE__ */ e($, { trim: !0, size: 14, strokeWidth: 2.5 }), label: "Next page", className: "data-table__pagination-btn", onClick: l.goNext, disabled: !l.canGoNext })
|
|
113
110
|
] })
|
|
114
111
|
] })
|
|
115
112
|
] })
|
|
116
113
|
] });
|
|
117
114
|
}
|
|
118
115
|
export {
|
|
119
|
-
|
|
116
|
+
Q as DataTable
|
|
120
117
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("react/jsx-runtime"),a=require("react"),S=require("../../ui/Alert/Alert.cjs"),B=require("../../ui/Toast/Toast.cjs"),L=require("../AiButton/AiButton.cjs"),z=require("../icons/AiIcons.cjs"),M=require("../Rise/Rise.cjs"),j=require("../ConfidenceBadge/ConfidenceBadge.cjs"),P=require("../../ui/Button/Button.cjs");;/* empty css */const U=require("../../../icons/glyphs/ArrowRight.cjs"),w=require("../../ui/Checkbox/Checkbox.cjs"),W={selectAll:"Select all",save:n=>`Save ${n}`,saved:n=>n===1?"Saved 1 change.":`Saved ${n} changes.`,selected:(n,l)=>`${n} of ${l} selected`,error:"Couldn't save",cancel:"Cancel",confidence:void 0},m=(n,...l)=>typeof n=="function"?n(...l):n,G=()=>s.jsx(U.default,{trim:!0,size:null,strokeWidth:2.2});function q(n,l="medium"){const f=j.CONFIDENCE_RANK[l]??j.CONFIDENCE_RANK.medium;return new Set((n||[]).filter(c=>c.defaultChecked!==void 0?c.defaultChecked:(j.CONFIDENCE_RANK[c.confidence]??2)>=f).map(c=>c.id))}function H({items:n=[],uncheckBelow:l="medium",alerts:f=[],title:c,description:N,onSave:p,onCancel:$,labels:I,className:F="",...T}){const i={...W,...I},[k,C]=a.useState(()=>q(n,l)),[v,E]=a.useState(!1),[r,g]=a.useState(null),b=a.useRef(null),y=a.useId().replace(/:/g,""),u=B.useToast(),A=typeof u?.toast=="function"&&u.toast.info!==u.toast,h=n.map(e=>e.id).join("|"),R=a.useRef(h);a.useEffect(()=>{R.current!==h&&(R.current=h,C(q(n,l)),g(null))},[h,n,l]);const o=n.filter(e=>k.has(e.id)).length,_=o===n.length&&n.length>0;a.useEffect(()=>{b.current&&(b.current.indeterminate=o>0&&!_)},[o,_]);const D=(e,t)=>C(x=>{const d=new Set(x);return t?d.add(e):d.delete(e),d}),K=async()=>{if(!p||!o||v)return;const e=n.filter(t=>k.has(t.id)).map(t=>t.id);E(!0),g(null);try{await p(e),A&&u.toast({tone:"success",title:m(i.saved,e.length)}),g({ok:!0,text:m(i.saved,e.length)})}catch(t){A&&u.toast({tone:"error",title:i.error,description:t?.message}),g({ok:!1,title:i.error,text:t?.message||""})}finally{E(!1)}};return s.jsxs("div",{className:`confidence-suggestions ${F}`.trim(),...T,children:[c||N?s.jsxs("div",{className:"confidence-suggestions__head",children:[c?s.jsx("p",{className:"confidence-suggestions__title",id:`cs-${y}-title`,children:c}):null,N?s.jsx("p",{className:"confidence-suggestions__desc",children:N}):null]}):null,f?.length?s.jsx("div",{className:"confidence-suggestions__alerts",children:f.map((e,t)=>e&&typeof e=="object"&&!Array.isArray(e)&&("text"in e||"title"in e)&&!e.$$typeof?s.jsx(S.default,{tone:e.tone||"warning",title:e.title,children:e.text},t):s.jsx(S.default,{tone:"warning",children:e},t))}):null,s.jsxs("ul",{className:"confidence-suggestions__list","aria-labelledby":c?`cs-${y}-title`:void 0,children:[n.length>1?s.jsx("li",{children:s.jsxs("label",{className:"confidence-suggestions__all",children:[s.jsx(w.Checkbox,{ref:b,className:"confidence-suggestions__check",checked:_,indeterminate:o>0&&!_,onChange:e=>C(e.target.checked?new Set(n.map(t=>t.id)):new Set)}),s.jsx("span",{children:m(i.selected,o,n.length)})]})}):null,n.map((e,t)=>{const x=k.has(e.id),d=`cs-${y}-r${t}`;return s.jsx("li",{...M.riseProps(t,{speed:"fast",className:"confidence-suggestions__item"}),children:s.jsxs("label",{className:"confidence-suggestions__row","data-off":x?void 0:"",children:[s.jsx(w.Checkbox,{className:"confidence-suggestions__check",checked:x,"aria-describedby":e.reason?d:void 0,onChange:O=>D(e.id,O.target.checked)}),s.jsxs("span",{className:"confidence-suggestions__main",children:[s.jsx("span",{className:"confidence-suggestions__name",children:e.title}),e.meta?s.jsx("span",{className:"confidence-suggestions__meta",children:e.meta}):null]}),s.jsxs("span",{className:"confidence-suggestions__side",children:[s.jsxs("span",{className:"confidence-suggestions__change",children:[e.from!=null?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"confidence-suggestions__from",children:e.from}),s.jsx(G,{})]}):null,s.jsx("span",{children:e.to})]}),s.jsx(j.default,{confidence:e.confidence,labels:i.confidence})]}),e.reason?s.jsx("p",{className:"confidence-suggestions__reason",id:d,children:e.reason}):null]})},e.id)})]}),r&&!r.ok&&!A?s.jsx(S.default,{tone:"danger",title:r.title,children:r.text}):null,s.jsxs("div",{className:"confidence-suggestions__footer",children:[s.jsx("p",{className:`confidence-suggestions__status${r?.ok?" confidence-suggestions__status--ok":""}`,role:"status","aria-live":"polite",children:r?.ok?r.text:null}),$?s.jsx(P.default,{shape:"pill",className:"confidence-suggestions__btn",onClick:$,children:i.cancel}):null,s.jsx(L.default,{variant:"solid",icon:s.jsx(z.CheckIcon,{size:14}),loading:v,disabled:!o||v||!p,onClick:K,children:m(i.save,o)})]})]})}exports.default=H;exports.initialChecked=q;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { jsxs as o, jsx as s, Fragment as
|
|
2
|
-
import { useState as A, useRef as R, useId as
|
|
1
|
+
import { jsxs as o, jsx as s, Fragment as U } from "react/jsx-runtime";
|
|
2
|
+
import { useState as A, useRef as R, useId as W, useEffect as B } from "react";
|
|
3
3
|
import S from "../../ui/Alert/Alert.mjs";
|
|
4
|
-
import { useToast as
|
|
5
|
-
import
|
|
6
|
-
import { CheckIcon as
|
|
7
|
-
import { riseProps as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
4
|
+
import { useToast as q } from "../../ui/Toast/Toast.mjs";
|
|
5
|
+
import G from "../AiButton/AiButton.mjs";
|
|
6
|
+
import { CheckIcon as H } from "../icons/AiIcons.mjs";
|
|
7
|
+
import { riseProps as J } from "../Rise/Rise.mjs";
|
|
8
|
+
import M, { CONFIDENCE_RANK as w } from "../ConfidenceBadge/ConfidenceBadge.mjs";
|
|
9
|
+
import Q from "../../ui/Button/Button.mjs";
|
|
10
10
|
import './ConfidenceSuggestions.css';/* empty css */
|
|
11
|
-
import
|
|
12
|
-
|
|
11
|
+
import V from "../../../icons/glyphs/ArrowRight.mjs";
|
|
12
|
+
import { Checkbox as F } from "../../ui/Checkbox/Checkbox.mjs";
|
|
13
|
+
const X = {
|
|
13
14
|
selectAll: "Select all",
|
|
14
15
|
save: (n) => `Save ${n}`,
|
|
15
16
|
saved: (n) => n === 1 ? "Saved 1 change." : `Saved ${n} changes.`,
|
|
@@ -17,72 +18,71 @@ const V = {
|
|
|
17
18
|
error: "Couldn't save",
|
|
18
19
|
cancel: "Cancel",
|
|
19
20
|
confidence: void 0
|
|
20
|
-
}, p = (n, ...l) => typeof n == "function" ? n(...l) : n,
|
|
21
|
-
function
|
|
21
|
+
}, p = (n, ...l) => typeof n == "function" ? n(...l) : n, Y = () => /* @__PURE__ */ s(V, { trim: !0, size: null, strokeWidth: 2.2 });
|
|
22
|
+
function L(n, l = "medium") {
|
|
22
23
|
const f = w[l] ?? w.medium;
|
|
23
24
|
return new Set(
|
|
24
25
|
(n || []).filter((c) => c.defaultChecked !== void 0 ? c.defaultChecked : (w[c.confidence] ?? 2) >= f).map((c) => c.id)
|
|
25
26
|
);
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
+
function ue({
|
|
28
29
|
items: n = [],
|
|
29
30
|
uncheckBelow: l = "medium",
|
|
30
31
|
alerts: f = [],
|
|
31
32
|
title: c,
|
|
32
|
-
description:
|
|
33
|
-
onSave:
|
|
33
|
+
description: N,
|
|
34
|
+
onSave: k,
|
|
34
35
|
onCancel: E,
|
|
35
|
-
labels:
|
|
36
|
-
className:
|
|
37
|
-
...
|
|
36
|
+
labels: T,
|
|
37
|
+
className: z = "",
|
|
38
|
+
...D
|
|
38
39
|
}) {
|
|
39
|
-
const i = { ...
|
|
40
|
+
const i = { ...X, ...T }, [v, C] = A(() => L(n, l)), [b, j] = A(!1), [r, g] = A(null), y = R(null), x = W().replace(/:/g, ""), u = q(), $ = typeof u?.toast == "function" && u.toast.info !== u.toast, m = n.map((e) => e.id).join("|"), I = R(m);
|
|
40
41
|
B(() => {
|
|
41
|
-
I.current !==
|
|
42
|
-
}, [
|
|
43
|
-
const
|
|
42
|
+
I.current !== m && (I.current = m, C(L(n, l)), g(null));
|
|
43
|
+
}, [m, n, l]);
|
|
44
|
+
const a = n.filter((e) => v.has(e.id)).length, h = a === n.length && n.length > 0;
|
|
44
45
|
B(() => {
|
|
45
|
-
|
|
46
|
-
}, [
|
|
47
|
-
const
|
|
48
|
-
const d = new Set(
|
|
46
|
+
y.current && (y.current.indeterminate = a > 0 && !h);
|
|
47
|
+
}, [a, h]);
|
|
48
|
+
const K = (e, t) => C((_) => {
|
|
49
|
+
const d = new Set(_);
|
|
49
50
|
return t ? d.add(e) : d.delete(e), d;
|
|
50
|
-
}),
|
|
51
|
-
if (!
|
|
52
|
-
const e = n.filter((t) =>
|
|
51
|
+
}), P = async () => {
|
|
52
|
+
if (!k || !a || b) return;
|
|
53
|
+
const e = n.filter((t) => v.has(t.id)).map((t) => t.id);
|
|
53
54
|
j(!0), g(null);
|
|
54
55
|
try {
|
|
55
|
-
await
|
|
56
|
+
await k(e), $ && u.toast({ tone: "success", title: p(i.saved, e.length) }), g({ ok: !0, text: p(i.saved, e.length) });
|
|
56
57
|
} catch (t) {
|
|
57
|
-
|
|
58
|
+
$ && u.toast({ tone: "error", title: i.error, description: t?.message }), g({ ok: !1, title: i.error, text: t?.message || "" });
|
|
58
59
|
} finally {
|
|
59
60
|
j(!1);
|
|
60
61
|
}
|
|
61
62
|
};
|
|
62
|
-
return /* @__PURE__ */ o("div", { className: `confidence-suggestions ${
|
|
63
|
-
c ||
|
|
64
|
-
c ? /* @__PURE__ */ s("p", { className: "confidence-suggestions__title", id: `cs-${
|
|
65
|
-
|
|
63
|
+
return /* @__PURE__ */ o("div", { className: `confidence-suggestions ${z}`.trim(), ...D, children: [
|
|
64
|
+
c || N ? /* @__PURE__ */ o("div", { className: "confidence-suggestions__head", children: [
|
|
65
|
+
c ? /* @__PURE__ */ s("p", { className: "confidence-suggestions__title", id: `cs-${x}-title`, children: c }) : null,
|
|
66
|
+
N ? /* @__PURE__ */ s("p", { className: "confidence-suggestions__desc", children: N }) : null
|
|
66
67
|
] }) : null,
|
|
67
68
|
f?.length ? /* @__PURE__ */ s("div", { className: "confidence-suggestions__alerts", children: f.map(
|
|
68
69
|
(e, t) => e && typeof e == "object" && !Array.isArray(e) && ("text" in e || "title" in e) && !e.$$typeof ? /* @__PURE__ */ s(S, { tone: e.tone || "warning", title: e.title, children: e.text }, t) : /* @__PURE__ */ s(S, { tone: "warning", children: e }, t)
|
|
69
70
|
) }) : null,
|
|
70
|
-
/* @__PURE__ */ o("ul", { className: "confidence-suggestions__list", "aria-labelledby": c ? `cs-${
|
|
71
|
+
/* @__PURE__ */ o("ul", { className: "confidence-suggestions__list", "aria-labelledby": c ? `cs-${x}-title` : void 0, children: [
|
|
71
72
|
n.length > 1 ? /* @__PURE__ */ s("li", { children: /* @__PURE__ */ o("label", { className: "confidence-suggestions__all", children: [
|
|
72
|
-
/* @__PURE__ */ s(
|
|
73
|
-
/* @__PURE__ */ s("span", { children: p(i.selected,
|
|
73
|
+
/* @__PURE__ */ s(F, { ref: y, className: "confidence-suggestions__check", checked: h, indeterminate: a > 0 && !h, onChange: (e) => C(e.target.checked ? new Set(n.map((t) => t.id)) : /* @__PURE__ */ new Set()) }),
|
|
74
|
+
/* @__PURE__ */ s("span", { children: p(i.selected, a, n.length) })
|
|
74
75
|
] }) }) : null,
|
|
75
76
|
n.map((e, t) => {
|
|
76
|
-
const
|
|
77
|
-
return /* @__PURE__ */ s("li", { ...
|
|
77
|
+
const _ = v.has(e.id), d = `cs-${x}-r${t}`;
|
|
78
|
+
return /* @__PURE__ */ s("li", { ...J(t, { speed: "fast", className: "confidence-suggestions__item" }), children: /* @__PURE__ */ o("label", { className: "confidence-suggestions__row", "data-off": _ ? void 0 : "", children: [
|
|
78
79
|
/* @__PURE__ */ s(
|
|
79
|
-
|
|
80
|
+
F,
|
|
80
81
|
{
|
|
81
|
-
type: "checkbox",
|
|
82
82
|
className: "confidence-suggestions__check",
|
|
83
|
-
checked:
|
|
83
|
+
checked: _,
|
|
84
84
|
"aria-describedby": e.reason ? d : void 0,
|
|
85
|
-
onChange: (
|
|
85
|
+
onChange: (O) => K(e.id, O.target.checked)
|
|
86
86
|
}
|
|
87
87
|
),
|
|
88
88
|
/* @__PURE__ */ o("span", { className: "confidence-suggestions__main", children: [
|
|
@@ -91,27 +91,27 @@ function re({
|
|
|
91
91
|
] }),
|
|
92
92
|
/* @__PURE__ */ o("span", { className: "confidence-suggestions__side", children: [
|
|
93
93
|
/* @__PURE__ */ o("span", { className: "confidence-suggestions__change", children: [
|
|
94
|
-
e.from != null ? /* @__PURE__ */ o(
|
|
94
|
+
e.from != null ? /* @__PURE__ */ o(U, { children: [
|
|
95
95
|
/* @__PURE__ */ s("span", { className: "confidence-suggestions__from", children: e.from }),
|
|
96
|
-
/* @__PURE__ */ s(
|
|
96
|
+
/* @__PURE__ */ s(Y, {})
|
|
97
97
|
] }) : null,
|
|
98
98
|
/* @__PURE__ */ s("span", { children: e.to })
|
|
99
99
|
] }),
|
|
100
|
-
/* @__PURE__ */ s(
|
|
100
|
+
/* @__PURE__ */ s(M, { confidence: e.confidence, labels: i.confidence })
|
|
101
101
|
] }),
|
|
102
102
|
e.reason ? /* @__PURE__ */ s("p", { className: "confidence-suggestions__reason", id: d, children: e.reason }) : null
|
|
103
103
|
] }) }, e.id);
|
|
104
104
|
})
|
|
105
105
|
] }),
|
|
106
|
-
|
|
106
|
+
r && !r.ok && !$ ? /* @__PURE__ */ s(S, { tone: "danger", title: r.title, children: r.text }) : null,
|
|
107
107
|
/* @__PURE__ */ o("div", { className: "confidence-suggestions__footer", children: [
|
|
108
|
-
/* @__PURE__ */ s("p", { className: `confidence-suggestions__status${
|
|
109
|
-
E ? /* @__PURE__ */ s(
|
|
110
|
-
/* @__PURE__ */ s(
|
|
108
|
+
/* @__PURE__ */ s("p", { className: `confidence-suggestions__status${r?.ok ? " confidence-suggestions__status--ok" : ""}`, role: "status", "aria-live": "polite", children: r?.ok ? r.text : null }),
|
|
109
|
+
E ? /* @__PURE__ */ s(Q, { shape: "pill", className: "confidence-suggestions__btn", onClick: E, children: i.cancel }) : null,
|
|
110
|
+
/* @__PURE__ */ s(G, { variant: "solid", icon: /* @__PURE__ */ s(H, { size: 14 }), loading: b, disabled: !a || b || !k, onClick: P, children: p(i.save, a) })
|
|
111
111
|
] })
|
|
112
112
|
] });
|
|
113
113
|
}
|
|
114
114
|
export {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
ue as default,
|
|
116
|
+
L as initialChecked
|
|
117
117
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),x=require("react"),Re=require("../../ui/StatusBadge/StatusBadge.cjs"),K=require("../../ui/TextField/TextField.cjs"),De=require("../../ui/Select/Select.cjs"),Be=require("../../ui/Alert/Alert.cjs"),Ee=require("../../ui/Toast/Toast.cjs"),Ue=require("../AiButton/AiButton.cjs"),H=require("../../ui/Button/Button.cjs"),L=require("../icons/AiIcons.cjs"),ze=require("../Rise/Rise.cjs"),w=require("./proposals.cjs");;/* empty css */const Le=require("../../../icons/glyphs/ArrowRight.cjs"),Oe=require("../../../icons/glyphs/CheckCircle.cjs"),We=require("../../../icons/glyphs/CloseCircle.cjs"),Me=require("../../../icons/glyphs/ExternalLink.cjs"),Ve=require("../../../icons/glyphs/Info.cjs"),Ke=require("../../../icons/glyphs/Refresh.cjs"),He=require("../../../icons/glyphs/Undo.cjs"),O={status:{pending:"Pending",applied:"Applied",rejected:"Rejected",stale:"Out of date",undone:"Undone"},approve:"Approve",reject:"Reject",pendingNote:"Nothing changes until you approve.",reason:"Why",field:"Field",was:"Was",now:"Now",wasValue:s=>`Was ${s}`,yes:"Yes",no:"No",empty:"empty",required:"Required",notNumber:"Enter a number",choose:"Choose…",to:"To",cc:"Cc",subject:"Subject",text:"Text",replyTo:"In reply to",recipientsHint:"Separate addresses with commas",item:"Item",quantity:"Qty",unitPrice:"Price",lineTotal:"Total",total:"Total",addPrice:s=>`Price for ${s}`,missingPrices:s=>s===1?"1 line needs a price before you can approve.":`${s} lines need a price before you can approve.`,records:s=>s===1?"record":"records",more:s=>`+${s} more`,skipped:(s,r)=>`${s} skipped${r?` (${r})`:""}`,alsoCloses:"Also closes",closed:s=>`Closed ${s}`,due:s=>`due ${s}`,applied:"Applied",rejected:"Rejected. Nothing changed.",stale:"The data changed after this was prepared. Ask again for a fresh proposal.",askAgain:"Ask again",openRecord:"Open record",undo:"Undo",undoUntil:s=>`until ${s}`,undone:"Undone. Everything is as it was.",error:"Couldn't save the change",undoError:"Couldn't undo the change"};function me(s,r){const o=w.parseAmount(s);if(Number.isNaN(o))return String(s??"");try{return new Intl.NumberFormat("en-US",{style:"currency",currency:r||"USD"}).format(o)}catch{return`${o.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})} ${r||""}`.trim()}}function he(s){if(!s)return"";const r=String(s),o=/^\d{4}-\d{2}-\d{2}$/.test(r),c=new Date(o?`${r}T00:00:00Z`:r);return Number.isNaN(c.getTime())?r:new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short",year:"numeric",...o?{timeZone:"UTC"}:null}).format(c)}function Ge(s){const r=new Date(s);if(Number.isNaN(r.getTime()))return String(s);const o=new Date().toDateString()===r.toDateString();return new Intl.DateTimeFormat("en-GB",o?{hour:"2-digit",minute:"2-digit"}:{weekday:"short",hour:"2-digit",minute:"2-digit"}).format(r)}const T=(s,...r)=>typeof s=="function"?s(...r):s,P=s=>s==null||String(s).trim()==="",je=()=>e.jsx(Le.default,{trim:!0,size:null,strokeWidth:2}),pe=()=>e.jsx(He.default,{size:null,strokeWidth:2}),Ze=()=>e.jsx(Me.default,{size:null,strokeWidth:2}),Qe=()=>e.jsx(Ve.default,{size:null,strokeWidth:2}),Xe=()=>e.jsx(Ke.default,{size:null,strokeWidth:2}),Ye=()=>e.jsx(We.default,{size:null,strokeWidth:2}),Je=()=>e.jsx(Oe.default,{size:null,strokeWidth:2}),ue={pending:"info",applied:"success",rejected:"neutral",stale:"warning",undone:"neutral"};function xe({status:s,undone:r=!1,labels:o,size:c="sm",className:p=""}){const n={...O.status,...o?.status||o},l=r?"undone":s in ue?s:"pending";return e.jsx(Re.default,{tone:ue[l],dot:!0,size:c,className:`proposal-status proposal-status--${l} ${p}`.trim(),children:n[l]})}function _e({changes:s=[],labels:r,className:o=""}){const c={...O,...r},p=n=>P(n)&&typeof n!="object"?e.jsx("span",{className:"proposal-card__empty",children:c.empty}):n;return e.jsx("div",{className:"proposal-card__table-wrap",children:e.jsxs("table",{className:`proposal-card__table proposal-card__diff ${o}`.trim(),children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:c.field}),e.jsx("th",{scope:"col",children:c.was}),e.jsx("th",{scope:"col","aria-hidden":"true"}),e.jsx("th",{scope:"col",children:c.now})]})}),e.jsx("tbody",{children:s.map((n,l)=>e.jsxs("tr",{children:[e.jsx("th",{scope:"row",children:n.label??n.field}),e.jsxs("td",{className:"proposal-card__old",children:[e.jsxs("span",{className:"proposal-card__sr",children:[c.was,": "]}),p(n.from)]}),e.jsx("td",{className:"proposal-card__arrow","aria-hidden":"true",children:e.jsx(je,{})}),e.jsxs("td",{className:"proposal-card__new",children:[e.jsxs("span",{className:"proposal-card__sr",children:[c.now,": "]}),p(n.to)]})]},n.field??l))})]})})}function G(s,r,o,c,p){if(P(r))return e.jsx("span",{className:"proposal-card__empty",children:c.empty});switch(s.type){case"money":return o.money(r,s.currency||p);case"date":return o.date(r);case"yesno":return/^(true|yes|1|y)$/i.test(String(r))?c.yes:c.no;case"enum":{const n=(s.options||[]).find(l=>(typeof l=="object"?l.value:l)===r);return n?typeof n=="object"?n.label:n:r}case"number":{const n=w.parseAmount(r);return Number.isNaN(n)?r:n.toLocaleString("en-US")}default:return r}}function es({f:s,value:r,onChange:o,problem:c,labels:p,currency:n,uid:l}){const N=c==="required"?p.required:c==="number"?p.notNumber:void 0,a=`${l}-${s.key}`,_={id:a,"aria-label":typeof s.label=="string"?s.label:void 0,error:N,required:!!s.required,size:"sm",className:"proposal-card__input"};switch(s.type){case"longtext":return e.jsx(K.default,{..._,multiline:!0,rows:2,maxRows:6,value:r??"",onChange:m=>o(m)});case"number":case"money":return e.jsx(K.default,{..._,inputMode:"decimal",suffix:s.type==="money"?s.currency||n:s.unit,value:r??"",onChange:m=>o(m)});case"date":return e.jsx(K.default,{..._,type:"date",value:r??"",onChange:m=>o(m)});case"enum":return e.jsx("div",{children:e.jsx(De.default,{id:a,size:"sm",options:s.options||[],value:r??null,placeholder:p.choose,ariaLabel:typeof s.label=="string"?s.label:void 0,required:s.required!==!1,error:N,onChange:m=>o(m)})});case"yesno":{const m=/^(true|yes|1|y)$/i.test(String(r)),S=!P(r)&&!m;return e.jsxs("div",{className:"proposal-card__yesno",role:"group","aria-label":typeof s.label=="string"?s.label:void 0,children:[e.jsx("button",{type:"button","aria-pressed":m,onClick:()=>o("yes"),children:p.yes}),e.jsx("button",{type:"button","aria-pressed":S,onClick:()=>o("no"),children:p.no})]})}default:return e.jsx(K.default,{..._,value:r??"",onChange:m=>o(m)})}}function ss({body:s,values:r,setValue:o,editing:c,problems:p,fmt:n,labels:l,uid:N}){return e.jsx("div",{className:"proposal-card__table-wrap",children:e.jsx("table",{className:"proposal-card__table proposal-card__fields",children:e.jsx("tbody",{children:(s.fields||[]).map(a=>{const _=r[a.key]!==void 0?r[a.key]:a.value,m=c&&a.editable,S=a.from!==void 0&&a.from!==null&&String(a.from)!==String(a.value),h=a.required||a.editable&&a.type==="enum"&&a.required!==!1;return e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",children:[m&&a.type!=="yesno"&&a.type!=="enum"?e.jsx("label",{htmlFor:`${N}-${a.key}`,children:a.label}):a.label,m&&h?e.jsx("span",{className:"proposal-card__req","aria-hidden":"true",children:"*"}):null]}),e.jsxs("td",{children:[m?e.jsxs(e.Fragment,{children:[e.jsx(es,{f:a,value:_,onChange:b=>o(a.key,b),problem:p[a.key],labels:l,currency:s.currency,uid:N}),S?e.jsx("span",{className:"proposal-card__was-hint",children:T(l.wasValue,G(a,a.from,n,l,s.currency))}):null]}):S?e.jsxs("span",{className:"proposal-card__was",children:[e.jsxs("span",{className:"proposal-card__old",children:[e.jsxs("span",{className:"proposal-card__sr",children:[l.was,": "]}),G(a,a.from,n,l,s.currency)]}),e.jsx(je,{}),e.jsxs("span",{className:"proposal-card__new",children:[e.jsxs("span",{className:"proposal-card__sr",children:[l.now,": "]}),G(a,_,n,l,s.currency)]})]}):G(a,_,n,l,s.currency),p[a.key]&&m&&a.type==="yesno"?e.jsx("span",{className:"proposal-card__field-error",children:l.required}):null]})]},a.key)})})})})}const B=s=>String(s??"").split(/[,;\n]/).map(r=>r.trim()).filter(Boolean);function rs({body:s,draft:r,setDraft:o,editing:c,problems:p,labels:n,uid:l}){const N=r.to??(s.to||[]).join(", "),a=r.cc??(s.cc||[]).join(", "),_=r.subject??s.subject??"",m=r.text??s.text??"",S=h=>e.jsx("span",{className:"proposal-card__recipients",children:h.map((b,g)=>e.jsx("span",{className:"proposal-card__chip",children:b},g))});return e.jsxs(e.Fragment,{children:[s.replyTo?e.jsxs("p",{className:"proposal-card__reply-to",children:[n.replyTo,": ",s.replyTo]}):null,e.jsx("div",{className:"proposal-card__message",children:c?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("label",{htmlFor:`${l}-to`,children:n.to}),e.jsx("input",{id:`${l}-to`,className:"proposal-card__msg-input",type:"text",inputMode:"email",value:N,"aria-invalid":p.to?!0:void 0,"aria-describedby":`${l}-to-hint`,onChange:h=>o({to:h.target.value})}),e.jsxs("span",{id:`${l}-to-hint`,className:"proposal-card__sr",children:[n.recipientsHint,p.to?`. ${n.required}`:""]})]}),e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("label",{htmlFor:`${l}-cc`,children:n.cc}),e.jsx("input",{id:`${l}-cc`,className:"proposal-card__msg-input",type:"text",inputMode:"email",value:a,onChange:h=>o({cc:h.target.value})})]}),e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("label",{htmlFor:`${l}-subject`,children:n.subject}),e.jsx("input",{id:`${l}-subject`,className:"proposal-card__msg-input proposal-card__msg-subject",type:"text",value:_,onChange:h=>o({subject:h.target.value})})]}),e.jsx("label",{htmlFor:`${l}-text`,className:"proposal-card__sr",children:n.text}),e.jsx("textarea",{id:`${l}-text`,className:"proposal-card__msg-text",value:m,rows:7,"aria-invalid":p.text?!0:void 0,onChange:h=>o({text:h.target.value})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("span",{children:n.to}),S(B(N))]}),B(a).length?e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("span",{children:n.cc}),S(B(a))]}):null,e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("span",{children:n.subject}),e.jsx("span",{className:"proposal-card__msg-subject",children:_})]}),e.jsx("p",{className:"proposal-card__msg-read",children:m})]})})]})}function ts({body:s,prices:r,setPrice:o,editing:c,problems:p,fmt:n,labels:l,uid:N}){const a=s.currency;let _=0,m=!0;const S=(s.lines||[]).map((h,b)=>{const g=r[b]!==void 0?r[b]:h.unitPrice,i=P(g)?NaN:w.parseAmount(g),u=w.parseAmount(h.quantity),A=Number.isNaN(i)||Number.isNaN(u)?NaN:i*u;return Number.isNaN(A)?m=!1:_+=A,{l:h,i:b,raw:g,lineTotal:A,needsInput:h.unitPrice==null||h.unitPrice===""}});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"proposal-card__table-wrap",tabIndex:0,role:"region","aria-label":l.item,children:e.jsxs("table",{className:"proposal-card__table proposal-card__lines",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:l.item}),e.jsx("th",{scope:"col",className:"num",children:l.quantity}),e.jsx("th",{scope:"col",className:"num",children:l.unitPrice}),e.jsx("th",{scope:"col",className:"num",children:l.lineTotal})]})}),e.jsx("tbody",{children:S.map(({l:h,i:b,raw:g,lineTotal:i,needsInput:u})=>e.jsxs("tr",{children:[e.jsx("td",{children:h.description}),e.jsxs("td",{className:"num",children:[h.quantity," ",h.unit?e.jsx("span",{className:"proposal-card__unit",children:h.unit}):null]}),e.jsx("td",{className:"num",children:u&&c?e.jsxs("span",{className:"proposal-card__price-input","data-filled":!P(g)&&!Number.isNaN(w.parseAmount(g))?"":void 0,children:[e.jsx("input",{id:`${N}-price-${b}`,type:"text",inputMode:"decimal",value:g??"",placeholder:"0.00","aria-label":T(l.addPrice,h.description),"aria-invalid":P(g)||Number.isNaN(w.parseAmount(g))?!0:void 0,onChange:A=>o(b,A.target.value)}),a?e.jsx("span",{"aria-hidden":"true",children:a}):null]}):P(g)?e.jsx("span",{className:"proposal-card__empty",children:"—"}):n.money(g,a)}),e.jsx("td",{className:"num",children:Number.isNaN(i)?e.jsx("span",{className:"proposal-card__empty",children:"—"}):n.money(i,a)})]},b))}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"row",colSpan:3,children:l.total}),e.jsx("td",{className:"num",children:m?n.money(_,a):e.jsx("span",{className:"proposal-card__empty",children:"—"})})]})})]})}),c&&p.lines?e.jsxs("p",{className:"proposal-card__missing",id:`${N}-missing`,children:[e.jsx(L.AlertIcon,{size:14}),T(l.missingPrices,p.lines)]}):null]})}function as({body:s,labels:r}){const o=s.sample||[],c=Math.max(0,(s.count||0)-o.length);return e.jsxs("div",{className:"proposal-card__bulk",children:[e.jsxs("p",{className:"proposal-card__bulk-count",children:[e.jsx("strong",{children:(s.count??0).toLocaleString("en-US")}),e.jsx("span",{children:T(r.records,s.count??0)})]}),s.preview?e.jsx("div",{children:s.preview}):null,o.length?e.jsxs("ul",{className:"proposal-card__sample",children:[o.map((p,n)=>e.jsx("li",{className:"proposal-card__chip",children:p},n)),c?e.jsx("li",{className:"proposal-card__more",children:T(r.more,c)}):null]}):null,s.skipped?e.jsx("p",{className:"proposal-card__skipped",children:T(r.skipped,s.skipped,s.skippedReason)}):null]})}function ns({body:s}){return e.jsx("div",{className:"proposal-card__table-wrap",tabIndex:0,role:"region","aria-label":typeof s.caption=="string"?s.caption:"Table",children:e.jsxs("table",{className:"proposal-card__table",children:[s.caption?e.jsx("caption",{className:"proposal-card__sr",children:s.caption}):null,e.jsx("thead",{children:e.jsx("tr",{children:(s.columns||[]).map((r,o)=>e.jsx("th",{scope:"col",children:r},o))})}),e.jsx("tbody",{children:(s.rows||[]).map((r,o)=>e.jsx("tr",{children:r.map((c,p)=>e.jsx("td",{children:c},p))},o))})]})})}const ee=s=>`${s?.id}|${s?.status}|${s?.undoneAt||""}|${s?.undoUntil||""}`;function os({proposal:s,decide:r,undo:o,onDecided:c,onNavigate:p,onAskAgain:n,onError:l,formatMoney:N=me,formatDate:a=he,formatTime:_=Ge,labels:m,index:S=0,rise:h=!0,className:b="",...g}){const i={...O,...m,status:{...O.status,...m?.status}},[u,A]=x.useState(s),[Ne,ge]=x.useState(()=>ee(s));ee(s)!==Ne&&(ge(ee(s)),A(s));const $=`pc-${x.useId().replace(/:/g,"")}`,[I,Z]=x.useState({}),[f,se]=x.useState({}),[Q,re]=x.useState({}),[fe,ye]=x.useState(!0),[X,te]=x.useState(()=>new Set((s?.closes||[]).filter(t=>!t.closed).map(t=>t.id))),[v,ae]=x.useState(null),[Y,W]=x.useState(null),[ne,oe]=x.useState(null),R=x.useRef(!0),M=Ee.useToast(),be=typeof M?.toast=="function"&&M.toast.info!==M.toast;x.useEffect(()=>(R.current=!0,()=>{R.current=!1}),[]);const le=x.useRef(s?.id);x.useEffect(()=>{le.current!==s?.id&&(le.current=s?.id,Z({}),se({}),re({}),te(new Set((s?.closes||[]).filter(t=>!t.closed).map(t=>t.id))),W(null))},[s]);const D=u?.undoUntil;x.useEffect(()=>{if(oe(Date.now()),!D)return;const t=Date.parse(D)-Date.now();if(!(t>0))return;const d=setTimeout(()=>R.current&&oe(Date.now()),Math.min(t+50,2**31-1));return()=>clearTimeout(d)},[D,u?.status]);const ce=x.useMemo(()=>({money:N,date:a}),[N,a]);if(!u)return null;const j=u.body||{kind:"custom",render:()=>null},q=u.status||"pending",F=!!u.undoneAt,ve=q==="pending"&&!F&&!v,E=q==="pending"&&!F,ke=j.kind==="fields"?I:j.kind==="message"?{...f.to!==void 0?{to:B(f.to)}:null,...f.text!==void 0?{text:f.text}:null}:j.kind==="lines"?{unitPrices:Q}:{},U=w.proposalProblems(u,ke),we=Object.keys(U).length===0&&(j.kind!=="custom"||fe),Se=()=>{let t={};if(j.kind==="fields")for(const d of j.fields||[])I[d.key]!==void 0&&String(I[d.key])!==String(d.value??"")&&(t[d.key]=I[d.key]);else if(j.kind==="message")f.to!==void 0&&(t.to=B(f.to)),f.cc!==void 0&&(t.cc=B(f.cc)),f.subject!==void 0&&f.subject!==j.subject&&(t.subject=f.subject),f.text!==void 0&&f.text!==j.text&&(t.text=f.text);else if(j.kind==="lines"){const d={};for(const[y,k]of Object.entries(Q))P(k)||(d[y]=String(w.parseAmount(k)));Object.keys(d).length&&(t.unitPrices=d)}else j.kind==="custom"&&(t={...I});return u.closes?.length&&(t.closes=u.closes.filter(d=>X.has(d.id)).map(d=>d.id)),Object.keys(t).length?t:void 0},$e=(t,d)=>{const y=t?.message||String(t||"");l?.(t),be?M.toast({tone:"error",title:d,description:y||void 0}):W({title:d,message:y})},J=async(t,d,y)=>{if(!v){ae(t),W(null);try{const k=await d();k&&R.current&&A(k),k&&c?.(k)}catch(k){R.current&&$e(k,y)}finally{R.current&&ae(null)}}},qe=()=>r&&J("approve",()=>r(u.id,!0,Se()),i.error),Ce=()=>r&&J("reject",()=>r(u.id,!1),i.error),Te=()=>o&&J("undo",()=>o(u.id),i.undoError),V=u.record||(u.href?{href:u.href,label:i.openRecord}:null),Ae=!!o&&q==="applied"&&!F&&!!D&&ne!=null&&Date.parse(D)>ne,Fe={edits:I,set:(t,d)=>Z(y=>({...y,[t]:d})),setValid:ye,editing:ve,status:q,formatMoney:N,formatDate:a};let C=null;switch(j.kind){case"diff":C=e.jsx(_e,{changes:j.changes,labels:i});break;case"fields":C=e.jsx(ss,{body:j,values:I,setValue:(t,d)=>Z(y=>({...y,[t]:d})),editing:E,problems:U,fmt:ce,labels:i,uid:$});break;case"message":C=e.jsx(rs,{body:j,draft:f,setDraft:t=>se(d=>({...d,...t})),editing:E,problems:U,labels:i,uid:$});break;case"lines":C=e.jsx(ts,{body:j,prices:Q,setPrice:(t,d)=>re(y=>({...y,[t]:d})),editing:E,problems:U,fmt:ce,labels:i,uid:$});break;case"bulk":C=e.jsx(as,{body:j,labels:i});break;case"table":C=e.jsx(ns,{body:j});break;case"custom":C=typeof j.render=="function"?j.render(Fe):null;break;default:C=null}const z=u.closes||[],ie=t=>t.closed??(q==="applied"&&!F&&X.has(t.id)),de=h?ze.riseProps(S):{className:"",style:void 0},Pe=["proposal-card",w.WIDE_KINDS.has(j.kind)?"proposal-card--wide":"",de.className,b].filter(Boolean).join(" "),Ie=t=>{!p||t.defaultPrevented||t.metaKey||t.ctrlKey||t.shiftKey||t.button>0||(t.preventDefault(),p(V.href))};return e.jsxs("div",{role:"group","aria-labelledby":`${$}-title ${$}-label`,"aria-busy":v?!0:void 0,className:Pe,style:de.style,"data-status":q,"data-kind":j.kind,"data-undone":F?"":void 0,...g,children:[e.jsxs("div",{className:"proposal-card__header",children:[e.jsx("span",{className:"proposal-card__mark","aria-hidden":"true",children:e.jsx(L.SparkleIcon,{size:15})}),e.jsxs("p",{className:"proposal-card__heading",children:[e.jsx("span",{id:`${$}-title`,className:"proposal-card__title",children:u.title}),e.jsx("span",{id:`${$}-label`,className:"proposal-card__label",children:u.label})]}),e.jsx("span",{className:"proposal-card__badge","aria-live":"polite",children:e.jsx(xe,{status:q,undone:F,labels:i.status})})]}),e.jsxs("div",{className:"proposal-card__body",children:[u.reason?e.jsxs("p",{className:"proposal-card__reason",children:[e.jsx(Qe,{}),e.jsxs("span",{children:[e.jsxs("span",{className:"proposal-card__reason-label",children:[i.reason,": "]}),u.reason]})]}):null,C,z.length&&E?e.jsxs("fieldset",{className:"proposal-card__closes",children:[e.jsx("legend",{children:i.alsoCloses}),e.jsx("ul",{children:z.map(t=>e.jsx("li",{children:e.jsxs("label",{className:"proposal-card__close-item","data-disabled":v?"":void 0,children:[e.jsx("input",{type:"checkbox",checked:X.has(t.id),disabled:!!v,onChange:d=>te(y=>{const k=new Set(y);return d.target.checked?k.add(t.id):k.delete(t.id),k})}),e.jsxs("span",{children:[t.title,t.due?e.jsx("span",{className:"proposal-card__close-due",children:T(i.due,a(t.due))}):null]})]})},t.id))})]}):null,z.length&&q==="applied"&&!F&&z.some(ie)?e.jsx("ul",{className:"proposal-card__closed-list","aria-label":i.alsoCloses,children:z.filter(ie).map(t=>e.jsxs("li",{className:"proposal-card__closed",children:[e.jsx(L.CheckIcon,{size:14}),T(i.closed,t.title)]},t.id))}):null]}),Y?e.jsx("div",{className:"proposal-card__error",children:e.jsx(Be.default,{tone:"danger",title:Y.title,dismissible:!0,onDismiss:()=>W(null),children:Y.message})}):null,e.jsx("div",{className:"proposal-card__footer",children:E?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"proposal-card__note",id:`${$}-note`,children:u.pendingNote??i.pendingNote}),e.jsxs("div",{className:"proposal-card__actions",children:[e.jsx(H.default,{shape:"pill",className:"proposal-card__btn",onClick:Ce,disabled:!!v||!r,loading:v==="reject",children:i.reject}),e.jsx(Ue.default,{variant:"solid",className:"proposal-card__approve",icon:v==="approve"?e.jsx("span",{className:"proposal-card__spinner","aria-hidden":"true"}):e.jsx(L.CheckIcon,{size:14}),loading:v==="approve",disabled:!we||!!v||!r,"aria-describedby":U.lines?`${$}-missing`:`${$}-note`,onClick:qe,children:u.approveLabel??i.approve})]})]}):F?e.jsxs("p",{className:"proposal-card__outcome",role:"status",children:[e.jsx(pe,{}),i.undone]}):q==="applied"?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"proposal-card__outcome proposal-card__outcome--applied",role:"status",children:[e.jsx(Je,{}),i.applied]}),e.jsxs("div",{className:"proposal-card__actions",children:[V?e.jsx(H.default,{variant:"ghost",shape:"pill",icon:e.jsx(Ze,{}),className:"proposal-card__btn proposal-card__btn--ghost",href:V.href,onClick:Ie,children:V.label??i.openRecord}):null,Ae?e.jsxs(H.default,{shape:"pill",icon:e.jsx(pe,{}),className:"proposal-card__btn",onClick:Te,disabled:!!v&&v!=="undo",loading:v==="undo",children:[i.undo,e.jsx("span",{className:"proposal-card__undo-until",suppressHydrationWarning:!0,children:T(i.undoUntil,_(D))})]}):null]})]}):q==="stale"?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"proposal-card__outcome proposal-card__outcome--stale",role:"status",children:[e.jsx(L.AlertIcon,{size:16}),i.stale]}),n?e.jsx("div",{className:"proposal-card__actions",children:e.jsx(H.default,{shape:"pill",icon:e.jsx(Xe,{}),className:"proposal-card__btn",onClick:()=>n(u),children:i.askAgain})}):null]}):e.jsxs("p",{className:"proposal-card__outcome",role:"status",children:[e.jsx(Ye,{}),i.rejected]})})]})}exports.approveEach=w.approveEach;exports.canApproveTogether=w.canApproveTogether;exports.parseAmount=w.parseAmount;exports.proposalProblems=w.proposalProblems;exports.DiffTable=_e;exports.PROPOSAL_LABELS=O;exports.ProposalStatusBadge=xe;exports.default=os;exports.defaultFormatDate=he;exports.defaultFormatMoney=me;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),x=require("react"),Re=require("../../ui/StatusBadge/StatusBadge.cjs"),K=require("../../ui/TextField/TextField.cjs"),De=require("../../ui/Select/Select.cjs"),Be=require("../../ui/Alert/Alert.cjs"),Ee=require("../../ui/Toast/Toast.cjs"),Ue=require("../AiButton/AiButton.cjs"),H=require("../../ui/Button/Button.cjs"),L=require("../icons/AiIcons.cjs"),ze=require("../Rise/Rise.cjs"),w=require("./proposals.cjs");;/* empty css */const Le=require("../../../icons/glyphs/ArrowRight.cjs"),Oe=require("../../../icons/glyphs/CheckCircle.cjs"),We=require("../../../icons/glyphs/CloseCircle.cjs"),Me=require("../../../icons/glyphs/ExternalLink.cjs"),Ve=require("../../../icons/glyphs/Info.cjs"),Ke=require("../../../icons/glyphs/Refresh.cjs"),He=require("../../../icons/glyphs/Undo.cjs"),Ge=require("../../ui/Checkbox/Checkbox.cjs"),O={status:{pending:"Pending",applied:"Applied",rejected:"Rejected",stale:"Out of date",undone:"Undone"},approve:"Approve",reject:"Reject",pendingNote:"Nothing changes until you approve.",reason:"Why",field:"Field",was:"Was",now:"Now",wasValue:s=>`Was ${s}`,yes:"Yes",no:"No",empty:"empty",required:"Required",notNumber:"Enter a number",choose:"Choose…",to:"To",cc:"Cc",subject:"Subject",text:"Text",replyTo:"In reply to",recipientsHint:"Separate addresses with commas",item:"Item",quantity:"Qty",unitPrice:"Price",lineTotal:"Total",total:"Total",addPrice:s=>`Price for ${s}`,missingPrices:s=>s===1?"1 line needs a price before you can approve.":`${s} lines need a price before you can approve.`,records:s=>s===1?"record":"records",more:s=>`+${s} more`,skipped:(s,r)=>`${s} skipped${r?` (${r})`:""}`,alsoCloses:"Also closes",closed:s=>`Closed ${s}`,due:s=>`due ${s}`,applied:"Applied",rejected:"Rejected. Nothing changed.",stale:"The data changed after this was prepared. Ask again for a fresh proposal.",askAgain:"Ask again",openRecord:"Open record",undo:"Undo",undoUntil:s=>`until ${s}`,undone:"Undone. Everything is as it was.",error:"Couldn't save the change",undoError:"Couldn't undo the change"};function me(s,r){const o=w.parseAmount(s);if(Number.isNaN(o))return String(s??"");try{return new Intl.NumberFormat("en-US",{style:"currency",currency:r||"USD"}).format(o)}catch{return`${o.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})} ${r||""}`.trim()}}function he(s){if(!s)return"";const r=String(s),o=/^\d{4}-\d{2}-\d{2}$/.test(r),c=new Date(o?`${r}T00:00:00Z`:r);return Number.isNaN(c.getTime())?r:new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short",year:"numeric",...o?{timeZone:"UTC"}:null}).format(c)}function Ze(s){const r=new Date(s);if(Number.isNaN(r.getTime()))return String(s);const o=new Date().toDateString()===r.toDateString();return new Intl.DateTimeFormat("en-GB",o?{hour:"2-digit",minute:"2-digit"}:{weekday:"short",hour:"2-digit",minute:"2-digit"}).format(r)}const T=(s,...r)=>typeof s=="function"?s(...r):s,P=s=>s==null||String(s).trim()==="",je=()=>e.jsx(Le.default,{trim:!0,size:null,strokeWidth:2}),pe=()=>e.jsx(He.default,{size:null,strokeWidth:2}),Qe=()=>e.jsx(Me.default,{size:null,strokeWidth:2}),Xe=()=>e.jsx(Ve.default,{size:null,strokeWidth:2}),Ye=()=>e.jsx(Ke.default,{size:null,strokeWidth:2}),Je=()=>e.jsx(We.default,{size:null,strokeWidth:2}),es=()=>e.jsx(Oe.default,{size:null,strokeWidth:2}),ue={pending:"info",applied:"success",rejected:"neutral",stale:"warning",undone:"neutral"};function xe({status:s,undone:r=!1,labels:o,size:c="sm",className:p=""}){const n={...O.status,...o?.status||o},l=r?"undone":s in ue?s:"pending";return e.jsx(Re.default,{tone:ue[l],dot:!0,size:c,className:`proposal-status proposal-status--${l} ${p}`.trim(),children:n[l]})}function _e({changes:s=[],labels:r,className:o=""}){const c={...O,...r},p=n=>P(n)&&typeof n!="object"?e.jsx("span",{className:"proposal-card__empty",children:c.empty}):n;return e.jsx("div",{className:"proposal-card__table-wrap",children:e.jsxs("table",{className:`proposal-card__table proposal-card__diff ${o}`.trim(),children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:c.field}),e.jsx("th",{scope:"col",children:c.was}),e.jsx("th",{scope:"col","aria-hidden":"true"}),e.jsx("th",{scope:"col",children:c.now})]})}),e.jsx("tbody",{children:s.map((n,l)=>e.jsxs("tr",{children:[e.jsx("th",{scope:"row",children:n.label??n.field}),e.jsxs("td",{className:"proposal-card__old",children:[e.jsxs("span",{className:"proposal-card__sr",children:[c.was,": "]}),p(n.from)]}),e.jsx("td",{className:"proposal-card__arrow","aria-hidden":"true",children:e.jsx(je,{})}),e.jsxs("td",{className:"proposal-card__new",children:[e.jsxs("span",{className:"proposal-card__sr",children:[c.now,": "]}),p(n.to)]})]},n.field??l))})]})})}function G(s,r,o,c,p){if(P(r))return e.jsx("span",{className:"proposal-card__empty",children:c.empty});switch(s.type){case"money":return o.money(r,s.currency||p);case"date":return o.date(r);case"yesno":return/^(true|yes|1|y)$/i.test(String(r))?c.yes:c.no;case"enum":{const n=(s.options||[]).find(l=>(typeof l=="object"?l.value:l)===r);return n?typeof n=="object"?n.label:n:r}case"number":{const n=w.parseAmount(r);return Number.isNaN(n)?r:n.toLocaleString("en-US")}default:return r}}function ss({f:s,value:r,onChange:o,problem:c,labels:p,currency:n,uid:l}){const N=c==="required"?p.required:c==="number"?p.notNumber:void 0,a=`${l}-${s.key}`,_={id:a,"aria-label":typeof s.label=="string"?s.label:void 0,error:N,required:!!s.required,size:"sm",className:"proposal-card__input"};switch(s.type){case"longtext":return e.jsx(K.default,{..._,multiline:!0,rows:2,maxRows:6,value:r??"",onChange:m=>o(m)});case"number":case"money":return e.jsx(K.default,{..._,inputMode:"decimal",suffix:s.type==="money"?s.currency||n:s.unit,value:r??"",onChange:m=>o(m)});case"date":return e.jsx(K.default,{..._,type:"date",value:r??"",onChange:m=>o(m)});case"enum":return e.jsx("div",{children:e.jsx(De.default,{id:a,size:"sm",options:s.options||[],value:r??null,placeholder:p.choose,ariaLabel:typeof s.label=="string"?s.label:void 0,required:s.required!==!1,error:N,onChange:m=>o(m)})});case"yesno":{const m=/^(true|yes|1|y)$/i.test(String(r)),S=!P(r)&&!m;return e.jsxs("div",{className:"proposal-card__yesno",role:"group","aria-label":typeof s.label=="string"?s.label:void 0,children:[e.jsx("button",{type:"button","aria-pressed":m,onClick:()=>o("yes"),children:p.yes}),e.jsx("button",{type:"button","aria-pressed":S,onClick:()=>o("no"),children:p.no})]})}default:return e.jsx(K.default,{..._,value:r??"",onChange:m=>o(m)})}}function rs({body:s,values:r,setValue:o,editing:c,problems:p,fmt:n,labels:l,uid:N}){return e.jsx("div",{className:"proposal-card__table-wrap",children:e.jsx("table",{className:"proposal-card__table proposal-card__fields",children:e.jsx("tbody",{children:(s.fields||[]).map(a=>{const _=r[a.key]!==void 0?r[a.key]:a.value,m=c&&a.editable,S=a.from!==void 0&&a.from!==null&&String(a.from)!==String(a.value),h=a.required||a.editable&&a.type==="enum"&&a.required!==!1;return e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",children:[m&&a.type!=="yesno"&&a.type!=="enum"?e.jsx("label",{htmlFor:`${N}-${a.key}`,children:a.label}):a.label,m&&h?e.jsx("span",{className:"proposal-card__req","aria-hidden":"true",children:"*"}):null]}),e.jsxs("td",{children:[m?e.jsxs(e.Fragment,{children:[e.jsx(ss,{f:a,value:_,onChange:b=>o(a.key,b),problem:p[a.key],labels:l,currency:s.currency,uid:N}),S?e.jsx("span",{className:"proposal-card__was-hint",children:T(l.wasValue,G(a,a.from,n,l,s.currency))}):null]}):S?e.jsxs("span",{className:"proposal-card__was",children:[e.jsxs("span",{className:"proposal-card__old",children:[e.jsxs("span",{className:"proposal-card__sr",children:[l.was,": "]}),G(a,a.from,n,l,s.currency)]}),e.jsx(je,{}),e.jsxs("span",{className:"proposal-card__new",children:[e.jsxs("span",{className:"proposal-card__sr",children:[l.now,": "]}),G(a,_,n,l,s.currency)]})]}):G(a,_,n,l,s.currency),p[a.key]&&m&&a.type==="yesno"?e.jsx("span",{className:"proposal-card__field-error",children:l.required}):null]})]},a.key)})})})})}const B=s=>String(s??"").split(/[,;\n]/).map(r=>r.trim()).filter(Boolean);function ts({body:s,draft:r,setDraft:o,editing:c,problems:p,labels:n,uid:l}){const N=r.to??(s.to||[]).join(", "),a=r.cc??(s.cc||[]).join(", "),_=r.subject??s.subject??"",m=r.text??s.text??"",S=h=>e.jsx("span",{className:"proposal-card__recipients",children:h.map((b,g)=>e.jsx("span",{className:"proposal-card__chip",children:b},g))});return e.jsxs(e.Fragment,{children:[s.replyTo?e.jsxs("p",{className:"proposal-card__reply-to",children:[n.replyTo,": ",s.replyTo]}):null,e.jsx("div",{className:"proposal-card__message",children:c?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("label",{htmlFor:`${l}-to`,children:n.to}),e.jsx("input",{id:`${l}-to`,className:"proposal-card__msg-input",type:"text",inputMode:"email",value:N,"aria-invalid":p.to?!0:void 0,"aria-describedby":`${l}-to-hint`,onChange:h=>o({to:h.target.value})}),e.jsxs("span",{id:`${l}-to-hint`,className:"proposal-card__sr",children:[n.recipientsHint,p.to?`. ${n.required}`:""]})]}),e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("label",{htmlFor:`${l}-cc`,children:n.cc}),e.jsx("input",{id:`${l}-cc`,className:"proposal-card__msg-input",type:"text",inputMode:"email",value:a,onChange:h=>o({cc:h.target.value})})]}),e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("label",{htmlFor:`${l}-subject`,children:n.subject}),e.jsx("input",{id:`${l}-subject`,className:"proposal-card__msg-input proposal-card__msg-subject",type:"text",value:_,onChange:h=>o({subject:h.target.value})})]}),e.jsx("label",{htmlFor:`${l}-text`,className:"proposal-card__sr",children:n.text}),e.jsx("textarea",{id:`${l}-text`,className:"proposal-card__msg-text",value:m,rows:7,"aria-invalid":p.text?!0:void 0,onChange:h=>o({text:h.target.value})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("span",{children:n.to}),S(B(N))]}),B(a).length?e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("span",{children:n.cc}),S(B(a))]}):null,e.jsxs("div",{className:"proposal-card__msg-row",children:[e.jsx("span",{children:n.subject}),e.jsx("span",{className:"proposal-card__msg-subject",children:_})]}),e.jsx("p",{className:"proposal-card__msg-read",children:m})]})})]})}function as({body:s,prices:r,setPrice:o,editing:c,problems:p,fmt:n,labels:l,uid:N}){const a=s.currency;let _=0,m=!0;const S=(s.lines||[]).map((h,b)=>{const g=r[b]!==void 0?r[b]:h.unitPrice,i=P(g)?NaN:w.parseAmount(g),u=w.parseAmount(h.quantity),A=Number.isNaN(i)||Number.isNaN(u)?NaN:i*u;return Number.isNaN(A)?m=!1:_+=A,{l:h,i:b,raw:g,lineTotal:A,needsInput:h.unitPrice==null||h.unitPrice===""}});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"proposal-card__table-wrap",tabIndex:0,role:"region","aria-label":l.item,children:e.jsxs("table",{className:"proposal-card__table proposal-card__lines",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:l.item}),e.jsx("th",{scope:"col",className:"num",children:l.quantity}),e.jsx("th",{scope:"col",className:"num",children:l.unitPrice}),e.jsx("th",{scope:"col",className:"num",children:l.lineTotal})]})}),e.jsx("tbody",{children:S.map(({l:h,i:b,raw:g,lineTotal:i,needsInput:u})=>e.jsxs("tr",{children:[e.jsx("td",{children:h.description}),e.jsxs("td",{className:"num",children:[h.quantity," ",h.unit?e.jsx("span",{className:"proposal-card__unit",children:h.unit}):null]}),e.jsx("td",{className:"num",children:u&&c?e.jsxs("span",{className:"proposal-card__price-input","data-filled":!P(g)&&!Number.isNaN(w.parseAmount(g))?"":void 0,children:[e.jsx("input",{id:`${N}-price-${b}`,type:"text",inputMode:"decimal",value:g??"",placeholder:"0.00","aria-label":T(l.addPrice,h.description),"aria-invalid":P(g)||Number.isNaN(w.parseAmount(g))?!0:void 0,onChange:A=>o(b,A.target.value)}),a?e.jsx("span",{"aria-hidden":"true",children:a}):null]}):P(g)?e.jsx("span",{className:"proposal-card__empty",children:"—"}):n.money(g,a)}),e.jsx("td",{className:"num",children:Number.isNaN(i)?e.jsx("span",{className:"proposal-card__empty",children:"—"}):n.money(i,a)})]},b))}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"row",colSpan:3,children:l.total}),e.jsx("td",{className:"num",children:m?n.money(_,a):e.jsx("span",{className:"proposal-card__empty",children:"—"})})]})})]})}),c&&p.lines?e.jsxs("p",{className:"proposal-card__missing",id:`${N}-missing`,children:[e.jsx(L.AlertIcon,{size:14}),T(l.missingPrices,p.lines)]}):null]})}function ns({body:s,labels:r}){const o=s.sample||[],c=Math.max(0,(s.count||0)-o.length);return e.jsxs("div",{className:"proposal-card__bulk",children:[e.jsxs("p",{className:"proposal-card__bulk-count",children:[e.jsx("strong",{children:(s.count??0).toLocaleString("en-US")}),e.jsx("span",{children:T(r.records,s.count??0)})]}),s.preview?e.jsx("div",{children:s.preview}):null,o.length?e.jsxs("ul",{className:"proposal-card__sample",children:[o.map((p,n)=>e.jsx("li",{className:"proposal-card__chip",children:p},n)),c?e.jsx("li",{className:"proposal-card__more",children:T(r.more,c)}):null]}):null,s.skipped?e.jsx("p",{className:"proposal-card__skipped",children:T(r.skipped,s.skipped,s.skippedReason)}):null]})}function os({body:s}){return e.jsx("div",{className:"proposal-card__table-wrap",tabIndex:0,role:"region","aria-label":typeof s.caption=="string"?s.caption:"Table",children:e.jsxs("table",{className:"proposal-card__table",children:[s.caption?e.jsx("caption",{className:"proposal-card__sr",children:s.caption}):null,e.jsx("thead",{children:e.jsx("tr",{children:(s.columns||[]).map((r,o)=>e.jsx("th",{scope:"col",children:r},o))})}),e.jsx("tbody",{children:(s.rows||[]).map((r,o)=>e.jsx("tr",{children:r.map((c,p)=>e.jsx("td",{children:c},p))},o))})]})})}const ee=s=>`${s?.id}|${s?.status}|${s?.undoneAt||""}|${s?.undoUntil||""}`;function ls({proposal:s,decide:r,undo:o,onDecided:c,onNavigate:p,onAskAgain:n,onError:l,formatMoney:N=me,formatDate:a=he,formatTime:_=Ze,labels:m,index:S=0,rise:h=!0,className:b="",...g}){const i={...O,...m,status:{...O.status,...m?.status}},[u,A]=x.useState(s),[Ne,ge]=x.useState(()=>ee(s));ee(s)!==Ne&&(ge(ee(s)),A(s));const $=`pc-${x.useId().replace(/:/g,"")}`,[I,Z]=x.useState({}),[f,se]=x.useState({}),[Q,re]=x.useState({}),[fe,ye]=x.useState(!0),[X,te]=x.useState(()=>new Set((s?.closes||[]).filter(t=>!t.closed).map(t=>t.id))),[v,ae]=x.useState(null),[Y,W]=x.useState(null),[ne,oe]=x.useState(null),R=x.useRef(!0),M=Ee.useToast(),be=typeof M?.toast=="function"&&M.toast.info!==M.toast;x.useEffect(()=>(R.current=!0,()=>{R.current=!1}),[]);const le=x.useRef(s?.id);x.useEffect(()=>{le.current!==s?.id&&(le.current=s?.id,Z({}),se({}),re({}),te(new Set((s?.closes||[]).filter(t=>!t.closed).map(t=>t.id))),W(null))},[s]);const D=u?.undoUntil;x.useEffect(()=>{if(oe(Date.now()),!D)return;const t=Date.parse(D)-Date.now();if(!(t>0))return;const d=setTimeout(()=>R.current&&oe(Date.now()),Math.min(t+50,2**31-1));return()=>clearTimeout(d)},[D,u?.status]);const ce=x.useMemo(()=>({money:N,date:a}),[N,a]);if(!u)return null;const j=u.body||{kind:"custom",render:()=>null},q=u.status||"pending",F=!!u.undoneAt,ve=q==="pending"&&!F&&!v,E=q==="pending"&&!F,ke=j.kind==="fields"?I:j.kind==="message"?{...f.to!==void 0?{to:B(f.to)}:null,...f.text!==void 0?{text:f.text}:null}:j.kind==="lines"?{unitPrices:Q}:{},U=w.proposalProblems(u,ke),we=Object.keys(U).length===0&&(j.kind!=="custom"||fe),Se=()=>{let t={};if(j.kind==="fields")for(const d of j.fields||[])I[d.key]!==void 0&&String(I[d.key])!==String(d.value??"")&&(t[d.key]=I[d.key]);else if(j.kind==="message")f.to!==void 0&&(t.to=B(f.to)),f.cc!==void 0&&(t.cc=B(f.cc)),f.subject!==void 0&&f.subject!==j.subject&&(t.subject=f.subject),f.text!==void 0&&f.text!==j.text&&(t.text=f.text);else if(j.kind==="lines"){const d={};for(const[y,k]of Object.entries(Q))P(k)||(d[y]=String(w.parseAmount(k)));Object.keys(d).length&&(t.unitPrices=d)}else j.kind==="custom"&&(t={...I});return u.closes?.length&&(t.closes=u.closes.filter(d=>X.has(d.id)).map(d=>d.id)),Object.keys(t).length?t:void 0},$e=(t,d)=>{const y=t?.message||String(t||"");l?.(t),be?M.toast({tone:"error",title:d,description:y||void 0}):W({title:d,message:y})},J=async(t,d,y)=>{if(!v){ae(t),W(null);try{const k=await d();k&&R.current&&A(k),k&&c?.(k)}catch(k){R.current&&$e(k,y)}finally{R.current&&ae(null)}}},qe=()=>r&&J("approve",()=>r(u.id,!0,Se()),i.error),Ce=()=>r&&J("reject",()=>r(u.id,!1),i.error),Te=()=>o&&J("undo",()=>o(u.id),i.undoError),V=u.record||(u.href?{href:u.href,label:i.openRecord}:null),Ae=!!o&&q==="applied"&&!F&&!!D&&ne!=null&&Date.parse(D)>ne,Fe={edits:I,set:(t,d)=>Z(y=>({...y,[t]:d})),setValid:ye,editing:ve,status:q,formatMoney:N,formatDate:a};let C=null;switch(j.kind){case"diff":C=e.jsx(_e,{changes:j.changes,labels:i});break;case"fields":C=e.jsx(rs,{body:j,values:I,setValue:(t,d)=>Z(y=>({...y,[t]:d})),editing:E,problems:U,fmt:ce,labels:i,uid:$});break;case"message":C=e.jsx(ts,{body:j,draft:f,setDraft:t=>se(d=>({...d,...t})),editing:E,problems:U,labels:i,uid:$});break;case"lines":C=e.jsx(as,{body:j,prices:Q,setPrice:(t,d)=>re(y=>({...y,[t]:d})),editing:E,problems:U,fmt:ce,labels:i,uid:$});break;case"bulk":C=e.jsx(ns,{body:j,labels:i});break;case"table":C=e.jsx(os,{body:j});break;case"custom":C=typeof j.render=="function"?j.render(Fe):null;break;default:C=null}const z=u.closes||[],ie=t=>t.closed??(q==="applied"&&!F&&X.has(t.id)),de=h?ze.riseProps(S):{className:"",style:void 0},Pe=["proposal-card",w.WIDE_KINDS.has(j.kind)?"proposal-card--wide":"",de.className,b].filter(Boolean).join(" "),Ie=t=>{!p||t.defaultPrevented||t.metaKey||t.ctrlKey||t.shiftKey||t.button>0||(t.preventDefault(),p(V.href))};return e.jsxs("div",{role:"group","aria-labelledby":`${$}-title ${$}-label`,"aria-busy":v?!0:void 0,className:Pe,style:de.style,"data-status":q,"data-kind":j.kind,"data-undone":F?"":void 0,...g,children:[e.jsxs("div",{className:"proposal-card__header",children:[e.jsx("span",{className:"proposal-card__mark","aria-hidden":"true",children:e.jsx(L.SparkleIcon,{size:15})}),e.jsxs("p",{className:"proposal-card__heading",children:[e.jsx("span",{id:`${$}-title`,className:"proposal-card__title",children:u.title}),e.jsx("span",{id:`${$}-label`,className:"proposal-card__label",children:u.label})]}),e.jsx("span",{className:"proposal-card__badge","aria-live":"polite",children:e.jsx(xe,{status:q,undone:F,labels:i.status})})]}),e.jsxs("div",{className:"proposal-card__body",children:[u.reason?e.jsxs("p",{className:"proposal-card__reason",children:[e.jsx(Xe,{}),e.jsxs("span",{children:[e.jsxs("span",{className:"proposal-card__reason-label",children:[i.reason,": "]}),u.reason]})]}):null,C,z.length&&E?e.jsxs("fieldset",{className:"proposal-card__closes",children:[e.jsx("legend",{children:i.alsoCloses}),e.jsx("ul",{children:z.map(t=>e.jsx("li",{children:e.jsxs("label",{className:"proposal-card__close-item","data-disabled":v?"":void 0,children:[e.jsx(Ge.Checkbox,{checked:X.has(t.id),disabled:!!v,onChange:d=>te(y=>{const k=new Set(y);return d.target.checked?k.add(t.id):k.delete(t.id),k})}),e.jsxs("span",{children:[t.title,t.due?e.jsx("span",{className:"proposal-card__close-due",children:T(i.due,a(t.due))}):null]})]})},t.id))})]}):null,z.length&&q==="applied"&&!F&&z.some(ie)?e.jsx("ul",{className:"proposal-card__closed-list","aria-label":i.alsoCloses,children:z.filter(ie).map(t=>e.jsxs("li",{className:"proposal-card__closed",children:[e.jsx(L.CheckIcon,{size:14}),T(i.closed,t.title)]},t.id))}):null]}),Y?e.jsx("div",{className:"proposal-card__error",children:e.jsx(Be.default,{tone:"danger",title:Y.title,dismissible:!0,onDismiss:()=>W(null),children:Y.message})}):null,e.jsx("div",{className:"proposal-card__footer",children:E?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"proposal-card__note",id:`${$}-note`,children:u.pendingNote??i.pendingNote}),e.jsxs("div",{className:"proposal-card__actions",children:[e.jsx(H.default,{shape:"pill",className:"proposal-card__btn",onClick:Ce,disabled:!!v||!r,loading:v==="reject",children:i.reject}),e.jsx(Ue.default,{variant:"solid",className:"proposal-card__approve",icon:v==="approve"?e.jsx("span",{className:"proposal-card__spinner","aria-hidden":"true"}):e.jsx(L.CheckIcon,{size:14}),loading:v==="approve",disabled:!we||!!v||!r,"aria-describedby":U.lines?`${$}-missing`:`${$}-note`,onClick:qe,children:u.approveLabel??i.approve})]})]}):F?e.jsxs("p",{className:"proposal-card__outcome",role:"status",children:[e.jsx(pe,{}),i.undone]}):q==="applied"?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"proposal-card__outcome proposal-card__outcome--applied",role:"status",children:[e.jsx(es,{}),i.applied]}),e.jsxs("div",{className:"proposal-card__actions",children:[V?e.jsx(H.default,{variant:"ghost",shape:"pill",icon:e.jsx(Qe,{}),className:"proposal-card__btn proposal-card__btn--ghost",href:V.href,onClick:Ie,children:V.label??i.openRecord}):null,Ae?e.jsxs(H.default,{shape:"pill",icon:e.jsx(pe,{}),className:"proposal-card__btn",onClick:Te,disabled:!!v&&v!=="undo",loading:v==="undo",children:[i.undo,e.jsx("span",{className:"proposal-card__undo-until",suppressHydrationWarning:!0,children:T(i.undoUntil,_(D))})]}):null]})]}):q==="stale"?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"proposal-card__outcome proposal-card__outcome--stale",role:"status",children:[e.jsx(L.AlertIcon,{size:16}),i.stale]}),n?e.jsx("div",{className:"proposal-card__actions",children:e.jsx(H.default,{shape:"pill",icon:e.jsx(Ye,{}),className:"proposal-card__btn",onClick:()=>n(u),children:i.askAgain})}):null]}):e.jsxs("p",{className:"proposal-card__outcome",role:"status",children:[e.jsx(Je,{}),i.rejected]})})]})}exports.approveEach=w.approveEach;exports.canApproveTogether=w.canApproveTogether;exports.parseAmount=w.parseAmount;exports.proposalProblems=w.proposalProblems;exports.DiffTable=_e;exports.PROPOSAL_LABELS=O;exports.ProposalStatusBadge=xe;exports.default=ls;exports.defaultFormatDate=he;exports.defaultFormatMoney=me;
|