import { b as generateId } from "./dist-uUUuTqM0.js";
import { m as actions } from "./module-CwMGazRD.js";
import "./module-DXiftdEs.js";
import { t as addSubteam } from "./creators-BZ72KijW.js";
import "./upgrade-manifest-0hATCABI.js";
import "./upgrade-manifest-CfTHUBCR.js";
import "./invoice-ovu7ZPDp.js";
import { D as useParentFolderForSelectedNode, c as setSelectedNode, g as useDocumentsInSelectedDrive, r as dispatchActions, y as useDrives } from "./dist-mx7YTOSV.js";
import "./chunk-VBDAOXYI-DjbP4DfS.js";
import { i as useSelectedBillingStatementDocument } from "./billing-statement-BYzQYDc9.js";
import "./splitted-input-diff-kvHJ6NHp.js";
import { d as PowerhouseButton, i as DocumentToolbar } from "./connect-MjNGHHUz-BfDIyhte.js";
import { n as Textarea } from "./with-field-validation-DGjBGqeq.js";
import { t as DatePicker } from "./date-picker-C1lWkDSy.js";
import { t as Select } from "./select-Z-3s_k3i.js";
import { t as Plus } from "./plus-BjHbY4gp.js";
import { a as NumberForm, l as Tag, n as formatNumber, o as InputField } from "./lineItems-AYD8VJAD.js";
import { t as Trash2 } from "./trash-2-BXVWMJFB.js";
import { t as X } from "./x-G7-4slQo.js";
import { n as expenseAccountOptions, t as budgetOptions } from "./tagMapping-BXJ_UNZP.js";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region editors/billing-statement/lineItemTags/lineItemTags.tsx
function LineItemTagsTable({ lineItems, onClose, dispatch, budgetOptions: budgetOptions$1 = budgetOptions }) {
	const handleReset = () => {
		lineItems.forEach((item) => {
			item.lineItemTag.forEach((tag) => {
				dispatch(actions.editLineItemTag({
					lineItemId: item.id,
					dimension: tag.dimension,
					value: "",
					label: ""
				}));
			});
		});
	};
	return /* @__PURE__ */ jsx("div", {
		className: "min-h-screen w-full bg-gradient-to-br from-slate-50 via-blue-50/30 to-slate-50 text-slate-800",
		children: /* @__PURE__ */ jsx("div", {
			className: "mx-auto w-full max-w-6xl px-4 py-10 sm:px-6 lg:px-8",
			children: /* @__PURE__ */ jsxs("div", {
				className: "overflow-hidden rounded-2xl border border-slate-200/60 bg-white text-slate-800 shadow-[0_18px_50px_rgba(15,23,42,0.10)]",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "relative border-b border-slate-200/60 bg-gradient-to-r from-slate-50 to-blue-50/50 px-6 py-5 text-slate-800",
					children: [
						/* @__PURE__ */ jsx("button", {
							type: "button",
							onClick: onClose,
							className: "absolute top-4 right-4 inline-flex items-center justify-center rounded-full border border-slate-300/60 bg-slate-100/50 p-2 text-slate-600 transition hover:bg-slate-200/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-slate-300 focus-visible:ring-offset-2 focus-visible:ring-offset-slate-50",
							"aria-label": "Close tag editor",
							children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5" })
						}),
						/* @__PURE__ */ jsxs("div", {
							className: "flex items-center gap-3",
							children: [/* @__PURE__ */ jsx("div", {
								className: "grid h-10 w-10 place-items-center rounded-xl border border-slate-200/60 bg-white",
								children: /* @__PURE__ */ jsx(Tag, { className: "h-5 w-5 text-slate-600" })
							}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
								className: "text-[11px] font-medium tracking-[0.22em] text-slate-500",
								children: "TAG EDITOR"
							}), /* @__PURE__ */ jsx("h2", {
								className: "text-xl font-medium tracking-tight",
								children: "Assign tags to line items"
							})] })]
						}),
						/* @__PURE__ */ jsx("div", {
							className: "flex items-center gap-2 mt-4",
							children: /* @__PURE__ */ jsx(PowerhouseButton, {
								color: "light",
								size: "small",
								onClick: handleReset,
								children: "Reset"
							})
						})
					]
				}), /* @__PURE__ */ jsxs("div", {
					className: "p-6",
					children: [/* @__PURE__ */ jsx("div", {
						className: "overflow-hidden rounded-xl border border-slate-200/60 bg-white shadow-[inset_0_1px_0_rgba(255,255,255,0.9)]",
						children: /* @__PURE__ */ jsx("div", {
							className: "overflow-x-auto",
							children: /* @__PURE__ */ jsxs("table", {
								className: "w-full border-collapse",
								children: [/* @__PURE__ */ jsx("thead", {
									className: "bg-gradient-to-r from-slate-50 to-blue-50/30 text-slate-800",
									children: /* @__PURE__ */ jsxs("tr", { children: [
										/* @__PURE__ */ jsx("th", {
											className: "border-b border-slate-200/60 px-3 py-3 text-left text-[11px] font-medium tracking-[0.20em] text-slate-600",
											children: "ITEM"
										}),
										/* @__PURE__ */ jsx("th", {
											className: "border-b border-slate-200/60 px-3 py-3 text-left text-[11px] font-medium tracking-[0.20em] text-slate-600",
											children: "PERIOD"
										}),
										/* @__PURE__ */ jsx("th", {
											className: "border-b border-slate-200/60 px-3 py-3 text-left text-[11px] font-medium tracking-[0.20em] text-slate-600",
											children: "EXPENSE ACCOUNT"
										}),
										/* @__PURE__ */ jsx("th", {
											className: "border-b border-slate-200/60 px-3 py-3 text-left text-[11px] font-medium tracking-[0.20em] text-slate-600",
											children: "BUDGET ALLOCATION"
										})
									] })
								}), /* @__PURE__ */ jsx("tbody", {
									className: "text-sm text-slate-700",
									children: lineItems.map((item) => /* @__PURE__ */ jsxs("tr", {
										className: "odd:bg-slate-50/30 even:bg-white hover:bg-blue-50/30",
										children: [
											/* @__PURE__ */ jsx("td", {
												className: "border-b border-slate-200/60 p-2",
												children: /* @__PURE__ */ jsx(InputField, {
													value: item.description,
													handleInputChange: () => {},
													onBlur: (e) => {
														dispatch(actions.editLineItem({
															id: item.id,
															description: e.target.value
														}));
													},
													className: "w-full text-xs"
												})
											}),
											/* @__PURE__ */ jsx("td", {
												className: "border-b border-slate-200/60 p-2 w-50",
												children: /* @__PURE__ */ jsx(DatePicker, {
													name: "period",
													dateFormat: "YYYY-MM-DD",
													autoClose: true,
													placeholder: "Select Period",
													value: item.lineItemTag.find((tag) => tag.dimension === "accounting-period")?.label || "",
													onChange: (e) => dispatch(actions.editLineItemTag({
														lineItemId: item.id,
														dimension: "accounting-period",
														value: new Date(e.target.value).toLocaleDateString("en-US", {
															year: "numeric",
															month: "numeric"
														}).split("/").reverse().join("/"),
														label: new Date(e.target.value).toLocaleDateString("en-US", {
															month: "long",
															year: "numeric"
														})
													})),
													className: "w-full text-xs bg-white"
												})
											}),
											/* @__PURE__ */ jsx("td", {
												className: "border-b border-slate-200/60 p-2",
												children: /* @__PURE__ */ jsx(Select, {
													options: expenseAccountOptions,
													value: item.lineItemTag.find((tag) => tag.dimension === "expense-account")?.value || "",
													placeholder: "Select Expense Account",
													searchable: true,
													onChange: (value) => {
														const selectedOption = expenseAccountOptions.find((option) => option.value === value);
														dispatch(actions.editLineItemTag({
															lineItemId: item.id,
															dimension: "expense-account",
															value: selectedOption?.value || "",
															label: selectedOption?.label
														}));
													},
													className: "w-full text-xs"
												})
											}),
											/* @__PURE__ */ jsx("td", {
												className: "border-b border-slate-200/60 p-2",
												children: /* @__PURE__ */ jsx(Select, {
													options: budgetOptions$1,
													value: item.lineItemTag.find((tag) => tag.dimension === "budget")?.value || "",
													placeholder: "Select Budget Allocation",
													searchable: true,
													onChange: (value) => {
														dispatch(actions.editLineItemTag({
															lineItemId: item.id,
															dimension: "budget",
															value,
															label: budgetOptions$1.find((option) => option.value === value)?.label
														}));
													}
												})
											})
										]
									}, item.id))
								})]
							})
						})
					}), /* @__PURE__ */ jsx("div", {
						className: "mt-4 text-xs text-slate-400",
						children: "Changes persist as you blur fields/selects."
					})]
				})]
			})
		})
	});
}
//#endregion
//#region editors/hooks/useOperationalHubSubteams.ts
/**
* Hook to access subteams from the Operational Hub Profile document in the current drive.
* Returns the subteams as SelectOptions for budget dropdowns and a function to add new subteams.
*/
function useOperationalHubSubteams() {
	const documentsInDrive = useDocumentsInSelectedDrive();
	const drives = useDrives();
	const operationalHubProfileDocument = useMemo(() => {
		if (!documentsInDrive) return null;
		return documentsInDrive.find((doc) => doc.header.documentType === "powerhouse/operational-hub-profile");
	}, [documentsInDrive]);
	const subteams = useMemo(() => {
		if (!operationalHubProfileDocument) return [];
		return operationalHubProfileDocument.state.global.subteams;
	}, [operationalHubProfileDocument]);
	const builderProfilesMap = useMemo(() => {
		const map = /* @__PURE__ */ new Map();
		if (!drives) return map;
		for (const drive of drives) if (drive.header.documentType === "powerhouse/document-drive" && drive.header.meta?.preferredEditor === "builder-team-admin") {
			const nodes = drive.state.global.nodes;
			for (const node of nodes) if (node.kind === "file" && "documentType" in node && node.documentType === "powerhouse/builder-profile") map.set(node.id, {
				id: node.id,
				name: node.name || "Untitled builder"
			});
		}
		return map;
	}, [drives]);
	return {
		subteams,
		budgetOptions: useMemo(() => {
			return subteams.map((subteamId) => {
				return {
					label: builderProfilesMap.get(subteamId)?.name || subteamId,
					value: subteamId
				};
			});
		}, [subteams, builderProfilesMap]),
		addNewSubteam: useCallback(async (subteamId) => {
			if (!operationalHubProfileDocument?.header.id) {
				console.error("No Operational Hub Profile document found");
				return false;
			}
			try {
				await dispatchActions(addSubteam({ subteam: subteamId }), operationalHubProfileDocument.header.id);
				return true;
			} catch (error) {
				console.error("Failed to add subteam:", error);
				return false;
			}
		}, [operationalHubProfileDocument?.header.id]),
		hasOperationalHubProfile: !!operationalHubProfileDocument
	};
}
//#endregion
//#region editors/billing-statement/components/lineItemsTable.tsx
const initialLineItem = {
	description: "",
	unit: "HOUR",
	quantity: "",
	unitPriceCash: "",
	unitPricePwt: ""
};
const LineItemsTable = (props) => {
	const { state, dispatch } = props;
	const { budgetOptions } = useOperationalHubSubteams();
	const [editingRow, setEditingRow] = useState(null);
	const [localLineItem, setLocalLineItem] = useState(initialLineItem);
	const [showTagTable, setShowTagTable] = useState(false);
	const [isAddingNew, setIsAddingNew] = useState(false);
	const [newLineItem, setNewLineItem] = useState(initialLineItem);
	const tableRef = useRef(null);
	useEffect(() => {
		function handleClickOutside(event) {
			const target = event.target;
			const isSelectMenu = target.closest("[role=\"listbox\"]") || target.closest("[role=\"option\"]");
			const isButton = target.closest("button");
			if (tableRef.current && !tableRef.current.contains(event.target) && !isSelectMenu && !isButton) {
				if (editingRow !== null) handleSave();
				if (isAddingNew) handleCancelAdd();
			}
		}
		document.addEventListener("mousedown", handleClickOutside);
		return () => {
			document.removeEventListener("mousedown", handleClickOutside);
		};
	}, [
		editingRow,
		localLineItem,
		isAddingNew,
		newLineItem
	]);
	const units = [
		{
			label: "Minute",
			value: "MINUTE"
		},
		{
			label: "Hour",
			value: "HOUR"
		},
		{
			label: "Day",
			value: "DAY"
		},
		{
			label: "Unit",
			value: "UNIT"
		}
	];
	const handleInputChange = (field, value) => {
		if (field === "unitPriceCash" || field === "unitPricePwt") {
			const regex = new RegExp(`^-?\\d*\\.?\\d{0,6}$`);
			const stringValue = String(value);
			if (regex.test(stringValue) || stringValue === "-") setLocalLineItem((prev) => ({
				...prev,
				[field]: value
			}));
		}
		setLocalLineItem((prev) => ({
			...prev,
			[field]: value
		}));
	};
	const handleSave = () => {
		const { description, unit, quantity, unitPriceCash, unitPricePwt } = localLineItem;
		if (description && unit && quantity !== "" && unitPriceCash !== "" && unitPricePwt !== "") {
			const qty = Number(quantity);
			const fiat = Number(unitPriceCash);
			const powt = Number(unitPricePwt);
			const originalItem = state.lineItems.find((item) => item.id === localLineItem.id);
			if (!originalItem || originalItem.description !== description || originalItem.unit !== unit || originalItem.quantity !== qty || originalItem.unitPriceCash !== fiat || originalItem.unitPricePwt !== powt) {
				const id = String(localLineItem.id);
				dispatch(actions.editLineItem({
					id,
					description,
					unit,
					quantity: qty,
					unitPriceCash: fiat,
					unitPricePwt: powt,
					totalPriceCash: qty * fiat,
					totalPricePwt: qty * powt
				}));
			}
			setEditingRow(null);
			setLocalLineItem(initialLineItem);
		}
	};
	const handleAddLineItem = () => {
		setIsAddingNew(true);
		setNewLineItem(initialLineItem);
	};
	const handleNewLineItemChange = (field, value) => {
		if (field === "unitPriceCash" || field === "unitPricePwt") {
			const regex = new RegExp(`^-?\\d*\\.?\\d{0,6}$`);
			const stringValue = String(value);
			if (regex.test(stringValue) || stringValue === "-") setNewLineItem((prev) => ({
				...prev,
				[field]: value
			}));
		} else setNewLineItem((prev) => ({
			...prev,
			[field]: value
		}));
	};
	const handleSaveNewLineItem = () => {
		const { description, unit, quantity, unitPriceCash, unitPricePwt } = newLineItem;
		if (description && unit && quantity !== "" && unitPriceCash !== "" && unitPricePwt !== "") {
			const qty = Number(quantity);
			const fiat = Number(unitPriceCash);
			const powt = Number(unitPricePwt);
			dispatch(actions.addLineItem({
				id: generateId(),
				description,
				unit,
				quantity: qty,
				unitPriceCash: fiat,
				unitPricePwt: powt,
				totalPriceCash: qty * fiat,
				totalPricePwt: qty * powt
			}));
			setIsAddingNew(false);
			setNewLineItem(initialLineItem);
		}
	};
	const handleCancelAdd = () => {
		setIsAddingNew(false);
		setNewLineItem(initialLineItem);
	};
	const handleDeleteLineItem = (id) => {
		if (editingRow !== null) {
			setEditingRow(null);
			setLocalLineItem(initialLineItem);
		}
		dispatch(actions.deleteLineItem({ id }));
	};
	if (showTagTable) return /* @__PURE__ */ jsx(LineItemTagsTable, {
		lineItems: state.lineItems,
		onClose: () => setShowTagTable(false),
		dispatch,
		budgetOptions: budgetOptions.length > 0 ? budgetOptions : void 0
	});
	return /* @__PURE__ */ jsxs("div", {
		className: "w-full",
		children: [/* @__PURE__ */ jsxs("div", {
			className: "flex items-center justify-between",
			children: [/* @__PURE__ */ jsxs("div", {
				className: "space-y-1",
				children: [/* @__PURE__ */ jsx("div", {
					className: "text-[11px] font-medium uppercase tracking-wider text-slate-400",
					children: "Line Items"
				}), /* @__PURE__ */ jsx("div", {
					className: "text-sm text-slate-400",
					children: "Double‑click a row to edit. Click outside to save."
				})]
			}), /* @__PURE__ */ jsx("div", {
				className: "flex items-center gap-3",
				children: /* @__PURE__ */ jsxs("button", {
					type: "button",
					onClick: () => setShowTagTable(!showTagTable),
					className: "group inline-flex items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 py-2 text-xs font-medium text-slate-600 shadow-sm transition hover:bg-slate-50 hover:border-slate-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/20 focus-visible:ring-offset-2",
					"aria-label": "Open tag editor",
					children: [/* @__PURE__ */ jsx(Tag, { className: "h-4 w-4 text-slate-400" }), "Tags"]
				})
			})]
		}), /* @__PURE__ */ jsxs("div", {
			className: "mt-5 overflow-hidden rounded-2xl border border-slate-100 bg-white shadow-sm",
			children: [
				/* @__PURE__ */ jsx("div", {
					className: "overflow-x-auto",
					ref: tableRef,
					children: /* @__PURE__ */ jsx("div", {
						className: "min-w-[980px]",
						children: /* @__PURE__ */ jsxs("table", {
							className: "w-full border-collapse text-sm",
							children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", {
								className: "bg-gradient-to-r from-slate-50 to-blue-50/30",
								children: [
									/* @__PURE__ */ jsx("th", {
										className: "w-10 border-b border-slate-100 px-2 py-3.5 text-center text-[11px] font-medium uppercase tracking-wide text-slate-500",
										children: "#"
									}),
									/* @__PURE__ */ jsx("th", {
										className: "w-[28rem] border-b border-slate-100 px-3 py-3.5 text-left text-[11px] font-medium uppercase tracking-wide text-slate-500",
										children: "Description"
									}),
									/* @__PURE__ */ jsx("th", {
										className: "w-44 border-b border-slate-100 px-3 py-3.5 text-left text-[11px] font-medium uppercase tracking-wide text-slate-500",
										children: "Unit"
									}),
									/* @__PURE__ */ jsx("th", {
										className: "w-20 border-b border-slate-100 px-3 py-3.5 text-right text-[11px] font-medium uppercase tracking-wide text-slate-500",
										children: "Qty"
									}),
									/* @__PURE__ */ jsx("th", {
										className: "w-28 border-b border-slate-100 px-3 py-3.5 text-right text-[11px] font-medium uppercase tracking-wide text-slate-500",
										children: "Fiat/Unit"
									}),
									/* @__PURE__ */ jsx("th", {
										className: "w-28 border-b border-slate-100 px-3 py-3.5 text-right text-[11px] font-medium uppercase tracking-wide text-slate-500",
										children: "POWT/Unit"
									}),
									/* @__PURE__ */ jsx("th", {
										className: "w-32 border-b border-slate-100 px-3 py-3.5 text-right text-[11px] font-medium uppercase tracking-wide text-slate-500",
										children: "Total Fiat"
									}),
									/* @__PURE__ */ jsx("th", {
										className: "w-32 border-b border-slate-100 px-3 py-3.5 text-right text-[11px] font-medium uppercase tracking-wide text-slate-500",
										children: "Total POWT"
									}),
									/* @__PURE__ */ jsx("th", { className: "w-16 border-b border-slate-100 px-2 py-3.5 text-center text-[11px] font-medium uppercase tracking-wide text-slate-500" })
								]
							}) }), /* @__PURE__ */ jsxs("tbody", {
								className: "text-slate-700",
								children: [state.lineItems.map((item, idx) => editingRow === idx ? /* @__PURE__ */ jsxs("tr", {
									className: "bg-blue-50/50 shadow-[inset_0_0_0_1px_rgba(59,130,246,0.15)]",
									children: [
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-2 py-3 text-center text-xs text-slate-400",
											children: idx + 1
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(InputField, {
												input: localLineItem.description,
												value: localLineItem.description,
												onBlur: () => {},
												handleInputChange: (e) => handleInputChange("description", e.target.value),
												className: "w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm shadow-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(Select, {
												options: units,
												value: localLineItem.unit,
												onChange: (value) => handleInputChange("unit", value),
												className: "w-44 rounded-xl border border-slate-200 bg-white px-2 py-2 text-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(NumberForm, {
												number: localLineItem.quantity,
												handleInputChange: (e) => handleInputChange("quantity", e.target.value),
												className: "w-24 rounded-xl border border-slate-200 bg-white px-3 py-2 text-right shadow-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(NumberForm, {
												number: localLineItem.unitPriceCash,
												handleInputChange: (e) => handleInputChange("unitPriceCash", String(e.target.value)),
												className: "w-28 rounded-xl border border-slate-200 bg-white px-3 py-2 text-right shadow-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(NumberForm, {
												number: localLineItem.unitPricePwt,
												handleInputChange: (e) => handleInputChange("unitPricePwt", e.target.value),
												className: "w-28 rounded-xl border border-slate-200 bg-white px-3 py-2 text-right shadow-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-3 text-right text-slate-500",
											children: localLineItem.quantity && localLineItem.unitPriceCash ? Number(localLineItem.quantity) * Number(localLineItem.unitPriceCash) : ""
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-3 text-right text-slate-500",
											children: localLineItem.quantity && localLineItem.unitPricePwt ? Number(localLineItem.quantity) * Number(localLineItem.unitPricePwt) : ""
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-2 py-3 text-center",
											children: /* @__PURE__ */ jsx("button", {
												type: "button",
												onClick: (e) => {
													e.stopPropagation();
													handleDeleteLineItem(String(localLineItem.id));
												},
												className: "inline-flex items-center justify-center rounded-lg p-1.5 text-red-400 transition hover:bg-red-50 hover:text-red-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-red-500/20 focus-visible:ring-offset-1",
												"aria-label": "Delete line item",
												children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" })
											})
										})
									]
								}, item.id) : /* @__PURE__ */ jsxs("tr", {
									className: "cursor-pointer odd:bg-slate-50/30 even:bg-white hover:bg-blue-50/30 transition-colors",
									onDoubleClick: () => {
										setEditingRow(idx);
										setLocalLineItem({ ...item });
									},
									children: [
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-2 py-3 text-center text-xs text-slate-400",
											children: idx + 1
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-3 py-3 text-slate-700",
											children: item.description
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-3 py-3 text-center text-xs font-medium tracking-wide text-slate-500",
											children: item.unit
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-3 py-3 text-right text-slate-700",
											children: item.quantity
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-3 py-3 text-right text-slate-700",
											children: formatNumber(item.unitPriceCash)
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-3 py-3 text-right text-slate-700",
											children: formatNumber(item.unitPricePwt)
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-3 py-3 text-right text-slate-700",
											children: formatNumber(item.totalPriceCash)
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-3 py-3 text-right text-slate-700",
											children: formatNumber(item.totalPricePwt)
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-50 px-2 py-3 text-center",
											children: /* @__PURE__ */ jsx("button", {
												type: "button",
												onClick: (e) => {
													e.stopPropagation();
													handleDeleteLineItem(item.id);
												},
												className: "inline-flex items-center justify-center rounded-lg p-1.5 text-red-400 transition hover:bg-red-50 hover:text-red-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-red-500/20 focus-visible:ring-offset-1",
												"aria-label": "Delete line item",
												children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" })
											})
										})
									]
								}, item.id)), isAddingNew && /* @__PURE__ */ jsxs("tr", {
									className: "bg-emerald-50/50 shadow-[inset_0_0_0_1px_rgba(16,185,129,0.15)]",
									children: [
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-2 py-3 text-center text-xs text-slate-400",
											children: state.lineItems.length + 1
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(InputField, {
												input: newLineItem.description,
												value: newLineItem.description,
												onBlur: () => {},
												handleInputChange: (e) => handleNewLineItemChange("description", e.target.value),
												className: "w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-sm shadow-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(Select, {
												options: units,
												value: newLineItem.unit,
												onChange: (value) => handleNewLineItemChange("unit", value),
												className: "w-44 rounded-xl border border-slate-200 bg-white px-2 py-2 text-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(NumberForm, {
												number: newLineItem.quantity,
												handleInputChange: (e) => handleNewLineItemChange("quantity", e.target.value),
												className: "w-24 rounded-xl border border-slate-200 bg-white px-3 py-2 text-right font-mono tabular-nums shadow-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(NumberForm, {
												number: newLineItem.unitPriceCash,
												handleInputChange: (e) => handleNewLineItemChange("unitPriceCash", String(e.target.value)),
												className: "w-28 rounded-xl border border-slate-200 bg-white px-3 py-2 text-right font-mono tabular-nums shadow-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-2",
											children: /* @__PURE__ */ jsx(NumberForm, {
												number: newLineItem.unitPricePwt,
												handleInputChange: (e) => handleNewLineItemChange("unitPricePwt", e.target.value),
												className: "w-28 rounded-xl border border-slate-200 bg-white px-3 py-2 text-right font-mono tabular-nums shadow-sm"
											})
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-3 text-right font-mono tabular-nums text-slate-500",
											children: newLineItem.quantity && newLineItem.unitPriceCash ? Number(newLineItem.quantity) * Number(newLineItem.unitPriceCash) : ""
										}),
										/* @__PURE__ */ jsx("td", {
											className: "border-b border-slate-100 px-3 py-3 text-right font-mono tabular-nums text-slate-500",
											children: newLineItem.quantity && newLineItem.unitPricePwt ? Number(newLineItem.quantity) * Number(newLineItem.unitPricePwt) : ""
										}),
										/* @__PURE__ */ jsx("td", { className: "border-b border-slate-100 px-2 py-3 text-center" })
									]
								})]
							})]
						})
					})
				}),
				!isAddingNew && /* @__PURE__ */ jsx("div", {
					className: "flex justify-center bg-gradient-to-r from-slate-50 to-blue-50/30 px-4 py-4",
					children: /* @__PURE__ */ jsxs("button", {
						onClick: handleAddLineItem,
						className: "inline-flex items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 py-2.5 text-xs font-medium text-slate-600 shadow-sm transition hover:bg-slate-50 hover:border-slate-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/20 focus-visible:ring-offset-2",
						children: [/* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 text-slate-400" }), "Add Line Item"]
					})
				}),
				isAddingNew && /* @__PURE__ */ jsxs("div", {
					className: "flex justify-center gap-3 bg-gradient-to-r from-slate-50 to-blue-50/30 px-4 py-4",
					children: [/* @__PURE__ */ jsx("button", {
						onClick: handleSaveNewLineItem,
						className: "rounded-xl bg-emerald-500 px-5 py-2.5 text-xs font-medium text-white shadow-sm transition hover:bg-emerald-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500/40 focus-visible:ring-offset-2",
						children: "Save Line Item"
					}), /* @__PURE__ */ jsx("button", {
						onClick: handleCancelAdd,
						className: "rounded-xl border border-slate-200 bg-white px-5 py-2.5 text-xs font-medium text-slate-600 shadow-sm transition hover:bg-slate-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-slate-300/40 focus-visible:ring-offset-2",
						children: "Cancel"
					})]
				})
			]
		})]
	});
};
//#endregion
//#region editors/billing-statement/editor.tsx
const currencyList = [
	{
		ticker: "USDS",
		crypto: true
	},
	{
		ticker: "USDC",
		crypto: true
	},
	{
		ticker: "DAI",
		crypto: true
	},
	{
		ticker: "EURC",
		crypto: true
	},
	{
		ticker: "EURE",
		crypto: true
	},
	{
		ticker: "USD",
		crypto: false
	},
	{
		ticker: "EUR",
		crypto: false
	},
	{
		ticker: "DKK",
		crypto: false
	},
	{
		ticker: "GBP",
		crypto: false
	},
	{
		ticker: "JPY",
		crypto: false
	},
	{
		ticker: "CNY",
		crypto: false
	},
	{
		ticker: "CHF",
		crypto: false
	}
];
function Editor(props) {
	const [doc, dispatch] = useSelectedBillingStatementDocument();
	const state = doc?.state.global;
	const [notes, setNotes] = useState(state?.notes ?? "");
	const parentFolder = useParentFolderForSelectedNode();
	if (!state) {
		console.log("Document state not found from document id", props.documentId);
		return null;
	}
	function handleClose() {
		setSelectedNode(parentFolder);
	}
	return /* @__PURE__ */ jsxs("div", {
		className: "min-h-screen w-full bg-gradient-to-br from-slate-50 via-blue-50/30 to-slate-50",
		children: [/* @__PURE__ */ jsx(DocumentToolbar, {
			document: doc,
			onClose: handleClose
		}), /* @__PURE__ */ jsx("div", {
			className: "w-full",
			children: /* @__PURE__ */ jsx("div", {
				className: "mx-auto w-full max-w-6xl px-4 py-10 sm:px-6 lg:px-8",
				children: /* @__PURE__ */ jsxs("div", {
					className: "overflow-hidden rounded-3xl border border-slate-200/60 bg-white shadow-[0_8px_30px_rgb(0,0,0,0.04)]",
					children: [/* @__PURE__ */ jsx("div", {
						className: "border-b border-slate-100 bg-gradient-to-r from-slate-50 to-blue-50/50 px-8 py-6",
						children: /* @__PURE__ */ jsxs("div", {
							className: "flex items-center justify-between",
							children: [/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("h1", {
								className: "text-3xl font-light tracking-tight text-slate-800",
								children: "Billing Statement"
							}) }), /* @__PURE__ */ jsxs("div", {
								className: "flex items-center gap-10",
								children: [/* @__PURE__ */ jsxs("div", {
									className: "flex flex-col items-end gap-1.5",
									children: [/* @__PURE__ */ jsx("div", {
										className: "text-[11px] font-medium uppercase tracking-wider text-slate-400",
										children: "Submitter"
									}), /* @__PURE__ */ jsx("div", {
										className: "text-sm font-medium text-slate-700",
										children: state.contributor
									})]
								}), /* @__PURE__ */ jsxs("div", {
									className: "flex flex-col items-end gap-1.5",
									children: [/* @__PURE__ */ jsx("div", {
										className: "text-[11px] font-medium uppercase tracking-wider text-slate-400",
										children: "Status"
									}), /* @__PURE__ */ jsx("span", {
										className: "inline-flex items-center rounded-full bg-blue-50 px-3 py-1 text-xs font-medium text-blue-700",
										children: String(state.status || "—")
									})]
								})]
							})]
						})
					}), /* @__PURE__ */ jsxs("div", {
						className: "px-8 py-8",
						children: [
							/* @__PURE__ */ jsxs("div", {
								className: "flex items-center justify-between rounded-2xl border border-slate-100 bg-slate-50/50 px-5 py-4",
								children: [/* @__PURE__ */ jsx("div", {
									className: "text-sm text-slate-500",
									children: "Keep edits lightweight: double‑click a row to edit, click outside to auto‑save."
								}), /* @__PURE__ */ jsxs("div", {
									className: "flex items-center gap-4",
									children: [/* @__PURE__ */ jsx("span", {
										className: "text-[11px] font-medium uppercase tracking-wider text-slate-400",
										children: "Currency"
									}), /* @__PURE__ */ jsx("div", {
										className: "rounded-xl border border-slate-200 bg-white px-3 py-2 shadow-sm",
										children: /* @__PURE__ */ jsx(Select, {
											className: "w-28",
											options: currencyList.map((currency) => ({
												value: currency.ticker,
												label: currency.ticker
											})),
											value: state.currency,
											onChange: (value) => {
												dispatch(actions.editBillingStatement({ currency: value }));
											}
										})
									})]
								})]
							}),
							/* @__PURE__ */ jsx("div", {
								className: "mt-6",
								children: /* @__PURE__ */ jsx(LineItemsTable, {
									state,
									dispatch
								})
							}),
							/* @__PURE__ */ jsxs("div", {
								className: "mt-8 grid gap-6 lg:grid-cols-2",
								children: [/* @__PURE__ */ jsxs("div", {
									className: "rounded-2xl border border-slate-100 bg-white p-5 shadow-sm",
									children: [/* @__PURE__ */ jsx(Textarea, {
										label: "Notes",
										placeholder: "Add notes",
										autoExpand: true,
										rows: 4,
										multiline: true,
										value: notes,
										onBlur: (e) => {
											const newValue = e.target.value;
											if (newValue !== state.notes) dispatch(actions.editBillingStatement({ notes: newValue }));
										},
										onChange: (e) => {
											setNotes(e.target.value);
										},
										className: "p-2"
									}), /* @__PURE__ */ jsx("div", {
										className: "mt-3 text-xs text-slate-400",
										children: "Tip: notes are saved by clicking outside of the textarea or pressing tab."
									})]
								}), /* @__PURE__ */ jsxs("div", {
									className: "rounded-2xl border border-slate-100 bg-white p-5 shadow-sm",
									children: [
										/* @__PURE__ */ jsxs("div", {
											className: "flex items-baseline justify-between",
											children: [/* @__PURE__ */ jsx("div", {
												className: "text-[11px] font-medium uppercase tracking-wider text-slate-400",
												children: "Totals"
											}), /* @__PURE__ */ jsx("div", {
												className: "text-xs text-slate-300",
												children: "read‑only"
											})]
										}),
										/* @__PURE__ */ jsx("div", {
											className: "mt-4 overflow-hidden rounded-xl border border-slate-100",
											children: /* @__PURE__ */ jsxs("table", {
												className: "w-full border-collapse",
												children: [/* @__PURE__ */ jsx("thead", {
													className: "bg-gradient-to-r from-slate-50 to-blue-50/30",
													children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
														className: "border-b border-slate-100 px-5 py-3.5 text-left text-xs font-medium uppercase tracking-wide text-slate-500",
														children: "Total Fiat"
													}), /* @__PURE__ */ jsx("th", {
														className: "border-b border-slate-100 px-5 py-3.5 text-left text-xs font-medium uppercase tracking-wide text-slate-500",
														children: "Total POWT"
													})] })
												}), /* @__PURE__ */ jsx("tbody", {
													className: "bg-white",
													children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("td", {
														className: "border-t border-slate-50 px-5 py-4 font-mono text-base tabular-nums text-slate-700",
														children: formatNumber(state.totalCash)
													}), /* @__PURE__ */ jsx("td", {
														className: "border-t border-slate-50 px-5 py-4 font-mono text-base tabular-nums text-slate-700",
														children: formatNumber(state.totalPowt)
													})] })
												})]
											})
										}),
										/* @__PURE__ */ jsx("div", {
											className: "mt-3 text-xs text-slate-400",
											children: "Totals update from line items."
										})
									]
								})]
							})
						]
					})]
				})
			})
		})]
	});
}
//#endregion
export { currencyList, Editor as default };

//# sourceMappingURL=editor-BTgxFVkH.js.map