import { b as generateId } from "./dist-CYoGQ6PD.mjs";
import { m as actions } from "./module-Dnc2DHmS.mjs";
import "./upgrade-manifest-CniiJeob.mjs";
import "./document-drive-BKF7N19I.mjs";
import "./chunk-VBDAOXYI-Dd3pepio.mjs";
import "./dist-LFSG_0Q3.mjs";
import { i as useSelectedGrantApplicationDocument } from "./grant-application-7PT_H477.mjs";
import "./load-design-tokens-B8bpWdLf.mjs";
import { t as DocumentToolbar } from "./connect-9ej7S5NE-DaHvmG3o.mjs";
import { useCallback, useState } from "react";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
//#region editors/grant-application-editor/components/constants.ts
const STAGE_CLASS = {
	DRAFT: "rfp-status-draft",
	SUBMITTED: "rfp-status-pending",
	OPENED: "rfp-status-pending",
	UNDER_REVIEW: "rfp-status-review",
	NEEDS_REVISION: "rfp-status-pending",
	REVISED: "rfp-status-review",
	APPROVED: "rfp-status-approved",
	CONDITIONALLY_APPROVED: "rfp-status-approved",
	REJECTED: "rfp-status-rejected",
	WITHDRAWN: "rfp-status-closed",
	FUNDED: "rfp-status-funded",
	COMPLETED: "rfp-status-completed"
};
const STAGE_LABEL = {
	DRAFT: "Draft",
	SUBMITTED: "Submitted",
	OPENED: "Opened",
	UNDER_REVIEW: "Under review",
	NEEDS_REVISION: "Needs revision",
	REVISED: "Revised",
	APPROVED: "Approved",
	CONDITIONALLY_APPROVED: "Conditionally approved",
	REJECTED: "Rejected",
	WITHDRAWN: "Withdrawn",
	FUNDED: "Funded",
	COMPLETED: "Completed"
};
//#endregion
//#region editors/grant-application-editor/components/ApplicationHeader.tsx
function ApplicationHeader({ state }) {
	const stage = state.reviewStage;
	return /* @__PURE__ */ jsx("header", {
		className: "rfp-header",
		children: /* @__PURE__ */ jsxs("div", {
			className: "rfp-header-row",
			children: [/* @__PURE__ */ jsxs("div", {
				className: "rfp-col",
				children: [
					/* @__PURE__ */ jsx("span", {
						className: "rfp-meta",
						children: "Grant Application · DAOIP-5"
					}),
					/* @__PURE__ */ jsxs("h1", {
						className: "rfp-h1",
						children: [
							state.projectName || "Unnamed project",
							" →",
							" ",
							state.grantPoolName || "pool"
						]
					}),
					/* @__PURE__ */ jsxs("p", {
						className: "rfp-hint",
						children: [
							"DAOIP-5 status: ",
							/* @__PURE__ */ jsx("strong", { children: state.status }),
							state.revisionCount > 0 ? ` · ${state.revisionCount} revision${state.revisionCount > 1 ? "s" : ""}` : ""
						]
					})
				]
			}), /* @__PURE__ */ jsx("span", {
				className: `rfp-status-badge ${STAGE_CLASS[stage] ?? "rfp-status-draft"}`,
				children: STAGE_LABEL[stage] ?? stage
			})]
		})
	});
}
//#endregion
//#region editors/grant-application-editor/components/ApplicationContent.tsx
function ApplicationContent({ state, on }) {
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-card rfp-section",
		children: [
			/* @__PURE__ */ jsx("h2", {
				className: "rfp-section-subtitle",
				children: "Application"
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("label", {
				className: "rfp-field",
				children: [/* @__PURE__ */ jsx("span", {
					className: "rfp-label",
					children: "Proposal content URL"
				}), /* @__PURE__ */ jsx("input", {
					className: "rfp-input",
					defaultValue: state.contentURI ?? "",
					placeholder: "https://… (your proposal markdown / PDF)",
					onBlur: (e) => on.setContent(e.target.value.trim())
				})]
			}),
			/* @__PURE__ */ jsxs("label", {
				className: "rfp-field",
				children: [/* @__PURE__ */ jsx("span", {
					className: "rfp-label",
					children: "Discussion thread"
				}), /* @__PURE__ */ jsx("input", {
					className: "rfp-input",
					defaultValue: state.discussionsTo ?? "",
					placeholder: "https://forum.example.org/…",
					onBlur: (e) => on.setDiscussions(e.target.value.trim())
				})]
			})
		]
	});
}
//#endregion
//#region editors/grant-application-editor/components/ApplicationMeta.tsx
function ApplicationMeta({ state, on }) {
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-card rfp-section",
		children: [
			/* @__PURE__ */ jsx("h2", {
				className: "rfp-section-subtitle",
				children: "Application metadata"
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-grid-2",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "rfp-field",
					children: [/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Grant pool"
					}), /* @__PURE__ */ jsxs("div", {
						className: "rfp-hint",
						children: [state.grantPoolName || "—", state.grantPoolId ? /* @__PURE__ */ jsxs("span", {
							className: "rfp-chip",
							style: { marginLeft: 8 },
							children: [String(state.grantPoolId).slice(0, 12), "…"]
						}) : null]
					})]
				}), /* @__PURE__ */ jsxs("div", {
					className: "rfp-field",
					children: [/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Project"
					}), /* @__PURE__ */ jsxs("div", {
						className: "rfp-hint",
						children: [state.projectName || "—", state.projectId ? /* @__PURE__ */ jsxs("span", {
							className: "rfp-chip",
							style: { marginLeft: 8 },
							children: [String(state.projectId).slice(0, 12), "…"]
						}) : null]
					})]
				})]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-grid-2",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "rfp-field",
					children: [/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Created"
					}), /* @__PURE__ */ jsx("div", {
						className: "rfp-hint",
						children: state.createdAt ? new Date(state.createdAt).toLocaleString() : "—"
					})]
				}), /* @__PURE__ */ jsxs("div", {
					className: "rfp-field",
					children: [/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "DAOIP-5 status"
					}), /* @__PURE__ */ jsxs("div", {
						className: "rfp-hint",
						children: [/* @__PURE__ */ jsx("strong", { children: state.status }), state.revisionCount > 0 ? /* @__PURE__ */ jsxs("span", {
							style: { marginLeft: 8 },
							children: [
								"· ",
								state.revisionCount,
								" revision",
								state.revisionCount > 1 ? "s" : ""
							]
						}) : null]
					})]
				})]
			}),
			/* @__PURE__ */ jsxs("label", {
				className: "rfp-field",
				children: [/* @__PURE__ */ jsx("span", {
					className: "rfp-label",
					children: "License URL"
				}), /* @__PURE__ */ jsx("input", {
					className: "rfp-input",
					defaultValue: state.licenseURI ?? "",
					placeholder: "https://opensource.org/licenses/MIT",
					onBlur: (e) => on.setLicenseUri(e.target.value.trim())
				})]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-grid-2",
				children: [/* @__PURE__ */ jsxs("label", {
					className: "rfp-field",
					children: [/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Completion rate (%)"
					}), /* @__PURE__ */ jsx("input", {
						className: "rfp-input",
						type: "number",
						min: "0",
						max: "100",
						step: "1",
						defaultValue: state.applicationCompletionRate != null ? String(state.applicationCompletionRate) : "",
						placeholder: "0 – 100",
						onBlur: (e) => {
							const raw = e.target.value.trim();
							if (!raw) {
								on.setCompletionRate(null);
								return;
							}
							const v = parseFloat(raw);
							if (Number.isFinite(v)) on.setCompletionRate(Math.max(0, Math.min(100, v)));
						}
					})]
				}), /* @__PURE__ */ jsxs("label", {
					className: "rfp-field",
					children: [/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Active"
					}), /* @__PURE__ */ jsxs("div", {
						className: "rfp-row",
						style: { paddingTop: 10 },
						children: [/* @__PURE__ */ jsx("input", {
							type: "checkbox",
							checked: !state.isInactive,
							onChange: (e) => on.setIsInactive(!e.target.checked),
							id: "is-active-toggle"
						}), /* @__PURE__ */ jsx("label", {
							htmlFor: "is-active-toggle",
							className: "rfp-hint",
							style: { cursor: "pointer" },
							children: state.isInactive ? "Marked inactive" : "Active application"
						})]
					})]
				})]
			}),
			(state.submitter || state.reviewedBy) && /* @__PURE__ */ jsxs("div", {
				className: "rfp-grid-2",
				children: [state.submitter ? /* @__PURE__ */ jsxs("div", {
					className: "rfp-field",
					children: [/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Submitted by"
					}), /* @__PURE__ */ jsxs("div", {
						className: "rfp-hint",
						children: [
							/* @__PURE__ */ jsx("span", {
								className: "rfp-chip",
								children: state.submitter.submitterType.toLowerCase().replace(/_/g, " ")
							}),
							/* @__PURE__ */ jsx("span", {
								style: { marginLeft: 8 },
								children: state.submitter.identifier
							}),
							state.submittedAt ? /* @__PURE__ */ jsx("div", {
								style: { marginTop: 4 },
								children: new Date(state.submittedAt).toLocaleString()
							}) : null
						]
					})]
				}) : null, state.reviewedBy ? /* @__PURE__ */ jsxs("div", {
					className: "rfp-field",
					children: [/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Reviewed by"
					}), /* @__PURE__ */ jsxs("div", {
						className: "rfp-hint",
						children: [state.reviewedBy, state.reviewedAt ? /* @__PURE__ */ jsx("div", {
							style: { marginTop: 4 },
							children: new Date(state.reviewedAt).toLocaleString()
						}) : null]
					})]
				}) : null]
			})
		]
	});
}
//#endregion
//#region editors/grant-application-editor/components/ApplicationSocials.tsx
function ApplicationSocials({ state, on }) {
	const [platform, setPlatform] = useState("");
	const [url, setUrl] = useState("");
	const handleAdd = () => {
		if (!platform.trim() || !url.trim()) return;
		on.addSocial(platform.trim(), url.trim());
		setPlatform("");
		setUrl("");
	};
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-card rfp-section",
		children: [
			/* @__PURE__ */ jsx("h2", {
				className: "rfp-section-subtitle",
				children: "Application socials"
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-row",
				children: [
					/* @__PURE__ */ jsx("input", {
						className: "rfp-input",
						style: { maxWidth: 180 },
						value: platform,
						onChange: (e) => setPlatform(e.target.value),
						placeholder: "Platform (Twitter, Farcaster…)"
					}),
					/* @__PURE__ */ jsx("input", {
						className: "rfp-input",
						style: { flex: 1 },
						value: url,
						onChange: (e) => setUrl(e.target.value),
						placeholder: "https://…",
						onKeyDown: (e) => {
							if (e.key === "Enter") {
								e.preventDefault();
								handleAdd();
							}
						}
					}),
					/* @__PURE__ */ jsx("button", {
						className: "rfp-btn-secondary",
						onClick: handleAdd,
						disabled: !platform.trim() || !url.trim(),
						children: "Add"
					})
				]
			}),
			state.socials.length === 0 ? /* @__PURE__ */ jsx("div", {
				className: "rfp-empty",
				children: "No socials yet."
			}) : /* @__PURE__ */ jsx("ul", {
				className: "rfp-list",
				children: state.socials.map((s) => /* @__PURE__ */ jsxs("li", {
					className: "rfp-list-item",
					children: [/* @__PURE__ */ jsxs("div", {
						className: "rfp-row",
						style: { gap: 12 },
						children: [/* @__PURE__ */ jsx("span", {
							className: "rfp-chip",
							children: s.platform
						}), /* @__PURE__ */ jsx("a", {
							href: s.url,
							target: "_blank",
							rel: "noreferrer",
							style: {
								color: "inherit",
								textDecoration: "none"
							},
							children: s.url
						})]
					}), /* @__PURE__ */ jsx("button", {
						className: "rfp-btn-ghost",
						onClick: () => on.removeSocial(s.id),
						"aria-label": "Remove social",
						children: "Remove"
					})]
				}, s.id))
			})
		]
	});
}
//#endregion
//#region editors/grant-application-editor/components/ApplicationFunding.tsx
const PAYMENT_TERMS = [
	"MILESTONE_BASED_FIXED_PRICE",
	"MILESTONE_BASED_ADVANCE_PAYMENT",
	"RETAINER_BASED",
	"VARIABLE_COST",
	"ESCROW"
];
const ADDRESS_TYPES = [
	"EthereumAddress",
	"CAIP10Address",
	"IBAN",
	"SWIFT_BIC",
	"StripePaymentMethod",
	"Other"
];
function formatAmount(a) {
	if (!a) return "—";
	const v = a.value;
	const u = a.unit || "";
	if (v == null) return "—";
	return `${v.toLocaleString()} ${u}`.trim();
}
function ApplicationFunding({ state, on }) {
	const [askValue, setAskValue] = useState("");
	const [askUnit, setAskUnit] = useState("USDC");
	const [approvedValue, setApprovedValue] = useState("");
	const [approvedUnit, setApprovedUnit] = useState("USDC");
	const [addressType, setAddressType] = useState(state.payoutAddress?.addressType ?? "EthereumAddress");
	const [addressValue, setAddressValue] = useState(state.payoutAddress?.value ?? "");
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-card rfp-section",
		children: [
			/* @__PURE__ */ jsx("h2", {
				className: "rfp-section-subtitle",
				children: "Funding"
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-col",
				children: [
					/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Funds asked"
					}),
					/* @__PURE__ */ jsxs("div", {
						className: "rfp-row",
						children: [
							/* @__PURE__ */ jsx("input", {
								className: "rfp-input",
								style: { flex: 1 },
								type: "number",
								step: "any",
								value: askValue,
								onChange: (e) => setAskValue(e.target.value),
								placeholder: "Amount (e.g. 50000)"
							}),
							/* @__PURE__ */ jsx("input", {
								className: "rfp-input",
								style: { maxWidth: 140 },
								value: askUnit,
								onChange: (e) => setAskUnit(e.target.value),
								placeholder: "USDC"
							}),
							/* @__PURE__ */ jsx("button", {
								className: "rfp-btn-secondary",
								disabled: !askValue.trim() || !askUnit.trim(),
								onClick: () => {
									const v = parseFloat(askValue);
									if (Number.isFinite(v)) {
										on.addFundsAsked(v, askUnit.trim());
										setAskValue("");
									}
								},
								children: "Add"
							})
						]
					}),
					state.fundsAsked.length === 0 ? /* @__PURE__ */ jsx("div", {
						className: "rfp-empty",
						children: "No amounts requested yet."
					}) : /* @__PURE__ */ jsx("ul", {
						className: "rfp-list",
						children: state.fundsAsked.map((entry) => /* @__PURE__ */ jsxs("li", {
							className: "rfp-list-item",
							children: [/* @__PURE__ */ jsx("span", { children: formatAmount(entry.amount) }), /* @__PURE__ */ jsx("button", {
								className: "rfp-btn-ghost",
								onClick: () => on.removeFundsAsked(entry.id),
								"aria-label": "Remove",
								children: "Remove"
							})]
						}, entry.id))
					}),
					/* @__PURE__ */ jsxs("label", {
						className: "rfp-field",
						children: [/* @__PURE__ */ jsx("span", {
							className: "rfp-label",
							children: "Total asked, USD (normalized)"
						}), /* @__PURE__ */ jsx("input", {
							className: "rfp-input",
							type: "number",
							step: "any",
							defaultValue: state.fundsAskedInUSD?.value ?? "",
							placeholder: "Total in USD",
							onBlur: (e) => {
								const v = parseFloat(e.target.value);
								if (Number.isFinite(v)) on.setFundsAskedUsd({
									value: v,
									unit: "USD"
								});
							}
						})]
					})
				]
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-col",
				children: [
					/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Funds approved"
					}),
					/* @__PURE__ */ jsxs("div", {
						className: "rfp-row",
						children: [
							/* @__PURE__ */ jsx("input", {
								className: "rfp-input",
								style: { flex: 1 },
								type: "number",
								step: "any",
								value: approvedValue,
								onChange: (e) => setApprovedValue(e.target.value),
								placeholder: "Approved amount"
							}),
							/* @__PURE__ */ jsx("input", {
								className: "rfp-input",
								style: { maxWidth: 140 },
								value: approvedUnit,
								onChange: (e) => setApprovedUnit(e.target.value),
								placeholder: "USDC"
							}),
							/* @__PURE__ */ jsx("button", {
								className: "rfp-btn-secondary",
								disabled: !approvedValue.trim() || !approvedUnit.trim(),
								onClick: () => {
									const v = parseFloat(approvedValue);
									if (Number.isFinite(v)) {
										on.addFundsApproved(v, approvedUnit.trim());
										setApprovedValue("");
									}
								},
								children: "Add"
							})
						]
					}),
					state.fundsApproved.length === 0 ? /* @__PURE__ */ jsx("div", {
						className: "rfp-empty",
						children: "No amounts approved yet."
					}) : /* @__PURE__ */ jsx("ul", {
						className: "rfp-list",
						children: state.fundsApproved.map((entry) => /* @__PURE__ */ jsx("li", {
							className: "rfp-list-item",
							children: /* @__PURE__ */ jsx("span", { children: formatAmount(entry.amount) })
						}, entry.id))
					}),
					/* @__PURE__ */ jsxs("label", {
						className: "rfp-field",
						children: [/* @__PURE__ */ jsx("span", {
							className: "rfp-label",
							children: "Total approved, USD"
						}), /* @__PURE__ */ jsx("input", {
							className: "rfp-input",
							type: "number",
							step: "any",
							defaultValue: state.fundsApprovedInUSD?.value ?? "",
							placeholder: "Total in USD",
							onBlur: (e) => {
								const v = parseFloat(e.target.value);
								if (Number.isFinite(v)) on.setFundsApprovedUsd({
									value: v,
									unit: "USD"
								});
							}
						})]
					})
				]
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-col",
				children: [
					/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Payout address"
					}),
					/* @__PURE__ */ jsxs("div", {
						className: "rfp-row",
						children: [
							/* @__PURE__ */ jsx("select", {
								className: "rfp-select",
								style: { maxWidth: 200 },
								value: addressType,
								onChange: (e) => setAddressType(e.target.value),
								children: ADDRESS_TYPES.map((t) => /* @__PURE__ */ jsx("option", {
									value: t,
									children: t
								}, t))
							}),
							/* @__PURE__ */ jsx("input", {
								className: "rfp-input",
								style: { flex: 1 },
								value: addressValue,
								onChange: (e) => setAddressValue(e.target.value),
								placeholder: "0x… or IBAN…"
							}),
							/* @__PURE__ */ jsx("button", {
								className: "rfp-btn-secondary",
								disabled: !addressValue.trim(),
								onClick: () => on.setPayoutAddress(addressType, addressValue.trim()),
								children: "Save"
							})
						]
					}),
					state.payoutAddress ? /* @__PURE__ */ jsxs("div", {
						className: "rfp-hint",
						children: [
							"Current: ",
							/* @__PURE__ */ jsx("strong", { children: state.payoutAddress.addressType }),
							" ·",
							" ",
							state.payoutAddress.value
						]
					}) : null
				]
			}),
			/* @__PURE__ */ jsxs("label", {
				className: "rfp-field",
				children: [/* @__PURE__ */ jsx("span", {
					className: "rfp-label",
					children: "Payment term"
				}), /* @__PURE__ */ jsxs("select", {
					className: "rfp-select",
					value: state.paymentTerm ?? "",
					onChange: (e) => {
						const v = e.target.value;
						if (v) on.setPaymentTerm(v);
					},
					children: [/* @__PURE__ */ jsx("option", {
						value: "",
						disabled: true,
						children: "Select payment term…"
					}), PAYMENT_TERMS.map((t) => /* @__PURE__ */ jsx("option", {
						value: t,
						children: t.toLowerCase().replace(/_/g, " ")
					}, t))]
				})]
			})
		]
	});
}
//#endregion
//#region editors/grant-application-editor/components/ApplicationPayouts.tsx
const PAYOUT_TYPES = [
	"OnchainTransaction",
	"CallDataEVM",
	"StripePayment",
	"InvoicePayment",
	"Other"
];
function ApplicationPayouts({ state, on }) {
	const [payoutType, setPayoutType] = useState("OnchainTransaction");
	const [value, setValue] = useState("");
	const [proof, setProof] = useState("");
	const canComplete = state.reviewStage === "FUNDED";
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-card rfp-section",
		children: [
			/* @__PURE__ */ jsx("h2", {
				className: "rfp-section-subtitle",
				children: "Payouts"
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-col",
				children: [
					/* @__PURE__ */ jsx("span", {
						className: "rfp-label",
						children: "Record a payout"
					}),
					/* @__PURE__ */ jsxs("div", {
						className: "rfp-grid-2",
						children: [/* @__PURE__ */ jsx("select", {
							className: "rfp-select",
							value: payoutType,
							onChange: (e) => setPayoutType(e.target.value),
							children: PAYOUT_TYPES.map((t) => /* @__PURE__ */ jsx("option", {
								value: t,
								children: t
							}, t))
						}), /* @__PURE__ */ jsx("input", {
							className: "rfp-input",
							value,
							onChange: (e) => setValue(e.target.value),
							placeholder: "tx hash / invoice id / payment id"
						})]
					}),
					/* @__PURE__ */ jsx("input", {
						className: "rfp-input",
						value: proof,
						onChange: (e) => setProof(e.target.value),
						placeholder: "Proof (etherscan URL, receipt link, etc.) — optional"
					}),
					/* @__PURE__ */ jsx("button", {
						className: "rfp-btn-primary",
						disabled: !value.trim(),
						onClick: () => {
							on.recordPayout(payoutType, value.trim(), proof.trim());
							setValue("");
							setProof("");
						},
						style: { alignSelf: "flex-start" },
						children: "Record payout"
					})
				]
			}),
			state.payouts.length === 0 ? /* @__PURE__ */ jsx("div", {
				className: "rfp-empty",
				children: "No payouts recorded yet."
			}) : /* @__PURE__ */ jsx("ul", {
				className: "rfp-list",
				children: state.payouts.map((p) => /* @__PURE__ */ jsx("li", {
					className: "rfp-list-item",
					children: /* @__PURE__ */ jsxs("div", {
						className: "rfp-col",
						style: {
							gap: 4,
							flex: 1
						},
						children: [
							/* @__PURE__ */ jsxs("div", {
								className: "rfp-row",
								style: { gap: 8 },
								children: [/* @__PURE__ */ jsx("span", {
									className: "rfp-chip",
									children: p.payoutType
								}), /* @__PURE__ */ jsx("strong", { children: p.value })]
							}),
							p.proof ? /* @__PURE__ */ jsx("a", {
								href: p.proof,
								target: "_blank",
								rel: "noreferrer",
								className: "rfp-hint",
								children: "Proof ↗"
							}) : null,
							/* @__PURE__ */ jsx("div", {
								className: "rfp-hint",
								children: new Date(p.timestamp).toLocaleString()
							})
						]
					})
				}, p.id))
			}),
			/* @__PURE__ */ jsx("button", {
				className: "rfp-btn-secondary",
				disabled: !canComplete,
				onClick: on.markCompleted,
				style: { alignSelf: "flex-start" },
				children: "Mark completed"
			})
		]
	});
}
//#endregion
//#region editors/grant-application-editor/components/ApplicationExtensions.tsx
function ApplicationExtensions({ state, on }) {
	const [expanded, setExpanded] = useState(false);
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-card rfp-section",
		children: [/* @__PURE__ */ jsxs("div", {
			className: "rfp-row",
			style: { justifyContent: "space-between" },
			children: [/* @__PURE__ */ jsxs("h2", {
				className: "rfp-section-subtitle",
				children: ["DAOIP-5 extensions ", !!state.extensions ? "· set" : "· empty"]
			}), /* @__PURE__ */ jsx("button", {
				type: "button",
				className: "rfp-btn-ghost",
				onClick: () => setExpanded((v) => !v),
				children: expanded ? "Hide" : "Show"
			})]
		}), expanded ? /* @__PURE__ */ jsxs(Fragment, { children: [
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("p", {
				className: "rfp-hint",
				children: [
					"JSON-serialized payload forwarded into the DAOIP-5 projection as",
					/* @__PURE__ */ jsx("code", { children: " extensions.powerhouse.*" }),
					". Custom integrator fields go here."
				]
			}),
			/* @__PURE__ */ jsxs("label", {
				className: "rfp-field",
				children: [/* @__PURE__ */ jsx("span", {
					className: "rfp-label",
					children: "Extensions (JSON)"
				}), /* @__PURE__ */ jsx("textarea", {
					className: "rfp-textarea",
					defaultValue: state.extensions ?? "",
					placeholder: "{\"vendorKey\": \"value\"}",
					onBlur: (e) => on.setExtensions(e.target.value),
					style: {
						fontFamily: "monospace",
						minHeight: 120
					}
				})]
			})
		] }) : null]
	});
}
//#endregion
//#region editors/grant-application-editor/components/ApplicantActions.tsx
function ApplicantActions({ state, on }) {
	const stage = state.reviewStage;
	const canSubmit = [
		"DRAFT",
		"REVISED",
		"NEEDS_REVISION"
	].includes(stage);
	const canMarkRevised = stage === "NEEDS_REVISION";
	const canWithdraw = [
		"DRAFT",
		"SUBMITTED",
		"OPENED",
		"UNDER_REVIEW",
		"NEEDS_REVISION",
		"REVISED"
	].includes(stage);
	const [identifier, setIdentifier] = useState("");
	if (!canSubmit && !canMarkRevised && !canWithdraw) return null;
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-card rfp-section",
		children: [
			/* @__PURE__ */ jsx("h2", {
				className: "rfp-section-subtitle",
				children: "Applicant actions"
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			canSubmit ? /* @__PURE__ */ jsxs("div", {
				className: "rfp-row",
				children: [/* @__PURE__ */ jsx("input", {
					className: "rfp-input",
					style: { flex: 1 },
					value: identifier,
					onChange: (e) => setIdentifier(e.target.value),
					placeholder: "Your DID (did:pkh:eip155:1:0x…)"
				}), /* @__PURE__ */ jsx("button", {
					type: "button",
					className: "rfp-btn-primary",
					disabled: !identifier.trim(),
					onClick: () => on.submit(identifier.trim()),
					children: stage === "NEEDS_REVISION" ? "Resubmit" : "Submit"
				})]
			}) : null,
			canMarkRevised ? /* @__PURE__ */ jsx("button", {
				type: "button",
				className: "rfp-btn-secondary",
				onClick: on.markRevised,
				style: { alignSelf: "flex-start" },
				children: "Mark as revised"
			}) : null,
			canWithdraw ? /* @__PURE__ */ jsx("button", {
				type: "button",
				className: "rfp-btn-ghost",
				onClick: () => on.withdraw("Withdrawn by applicant"),
				style: {
					alignSelf: "flex-start",
					color: "var(--rfp-error)"
				},
				children: "Withdraw application"
			}) : null
		]
	});
}
//#endregion
//#region editors/grant-application-editor/components/ReviewerActions.tsx
function ReviewerActions({ state, on }) {
	const stage = state.reviewStage;
	const canOpen = stage === "SUBMITTED";
	const canStartReview = ["SUBMITTED", "OPENED"].includes(stage);
	const canRequestRevision = stage === "UNDER_REVIEW";
	const canDecide = ["UNDER_REVIEW", "REVISED"].includes(stage);
	const [reviewerDid, setReviewerDid] = useState("");
	const [feedback, setFeedback] = useState("");
	if (!canOpen && !canStartReview && !canRequestRevision && !canDecide) return null;
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-card rfp-section",
		children: [
			/* @__PURE__ */ jsx("h2", {
				className: "rfp-section-subtitle",
				children: "Reviewer actions"
			}),
			/* @__PURE__ */ jsx("hr", { className: "rfp-divider" }),
			/* @__PURE__ */ jsxs("label", {
				className: "rfp-field",
				children: [/* @__PURE__ */ jsx("span", {
					className: "rfp-label",
					children: "Reviewer DID"
				}), /* @__PURE__ */ jsx("input", {
					className: "rfp-input",
					value: reviewerDid,
					onChange: (e) => setReviewerDid(e.target.value),
					placeholder: "did:pkh:eip155:1:0x…"
				})]
			}),
			/* @__PURE__ */ jsxs("div", {
				className: "rfp-row",
				style: {
					gap: 12,
					flexWrap: "wrap"
				},
				children: [
					canOpen ? /* @__PURE__ */ jsx("button", {
						type: "button",
						className: "rfp-btn-ghost",
						onClick: on.openApplication,
						children: "Open (acknowledge)"
					}) : null,
					canStartReview ? /* @__PURE__ */ jsx("button", {
						type: "button",
						className: "rfp-btn-secondary",
						disabled: !reviewerDid.trim(),
						onClick: () => on.startReview(reviewerDid.trim()),
						children: "Start review"
					}) : null,
					canDecide ? /* @__PURE__ */ jsxs(Fragment, { children: [
						/* @__PURE__ */ jsx("button", {
							type: "button",
							className: "rfp-btn-primary",
							disabled: !reviewerDid.trim(),
							onClick: () => on.approve(reviewerDid.trim()),
							children: "Approve"
						}),
						/* @__PURE__ */ jsx("button", {
							type: "button",
							className: "rfp-btn-secondary",
							disabled: !reviewerDid.trim() || !feedback.trim(),
							onClick: () => on.conditionallyApprove(reviewerDid.trim(), feedback.trim()),
							children: "Conditional approve"
						}),
						/* @__PURE__ */ jsx("button", {
							type: "button",
							className: "rfp-btn-secondary",
							disabled: !reviewerDid.trim() || !feedback.trim(),
							onClick: () => on.reject(reviewerDid.trim(), feedback.trim()),
							style: { color: "var(--rfp-error)" },
							children: "Reject"
						})
					] }) : null
				]
			}),
			canRequestRevision || canDecide ? /* @__PURE__ */ jsxs("label", {
				className: "rfp-field",
				children: [/* @__PURE__ */ jsx("span", {
					className: "rfp-label",
					children: "Feedback (for rejection or revision request)"
				}), /* @__PURE__ */ jsx("textarea", {
					className: "rfp-textarea",
					value: feedback,
					onChange: (e) => setFeedback(e.target.value),
					placeholder: "What needs to change or why reject…"
				})]
			}) : null,
			canRequestRevision ? /* @__PURE__ */ jsx("button", {
				type: "button",
				className: "rfp-btn-secondary",
				disabled: !feedback.trim(),
				onClick: () => {
					on.requestRevision(feedback.trim());
					setFeedback("");
				},
				style: { alignSelf: "flex-start" },
				children: "Request revision"
			}) : null
		]
	});
}
//#endregion
//#region editors/grant-application-editor/components/ReviewerFeedbackCard.tsx
function ReviewerFeedbackCard({ feedback }) {
	return /* @__PURE__ */ jsxs("section", {
		className: "rfp-feedback-card",
		children: [/* @__PURE__ */ jsx("h3", {
			className: "rfp-feedback-card-title",
			children: "Reviewer feedback"
		}), /* @__PURE__ */ jsx("p", {
			className: "rfp-feedback-card-body",
			children: feedback
		})]
	});
}
//#endregion
//#region editors/grant-application-editor/editor.tsx
function Editor() {
	const [document, dispatch] = useSelectedGrantApplicationDocument();
	const setContent = useCallback((contentURI) => dispatch(actions.setAppContentUri({ contentURI })), [dispatch]);
	const setDiscussions = useCallback((discussionsTo) => dispatch(actions.setDiscussionsTo({ discussionsTo })), [dispatch]);
	const setLicenseUri = useCallback((licenseURI) => dispatch(actions.setAppLicenseUri({ licenseURI })), [dispatch]);
	const setIsInactive = useCallback((v) => dispatch(actions.setIsInactive({ isInactive: v })), [dispatch]);
	const setCompletionRate = useCallback((v) => dispatch(actions.setCompletionRate({ applicationCompletionRate: v })), [dispatch]);
	const addSocial = useCallback((platform, url) => dispatch(actions.addAppSocial({
		id: generateId(),
		platform,
		url
	})), [dispatch]);
	const removeSocial = useCallback((id) => dispatch(actions.removeAppSocial({ id })), [dispatch]);
	const addFundsAsked = useCallback((value, unit) => dispatch(actions.addFundsAsked({
		id: generateId(),
		amount: {
			value,
			unit
		}
	})), [dispatch]);
	const removeFundsAsked = useCallback((id) => dispatch(actions.removeFundsAsked({ id })), [dispatch]);
	const setFundsAskedUsd = useCallback((v) => {
		if (v.value == null || !v.unit) return;
		dispatch(actions.setFundsAskedUsd({ fundsAskedInUSD: {
			value: v.value,
			unit: v.unit
		} }));
	}, [dispatch]);
	const addFundsApproved = useCallback((value, unit) => dispatch(actions.addFundsApproved({
		id: generateId(),
		amount: {
			value,
			unit
		}
	})), [dispatch]);
	const setFundsApprovedUsd = useCallback((v) => {
		if (v.value == null || !v.unit) return;
		dispatch(actions.setFundsApprovedUsd({ fundsApprovedInUSD: {
			value: v.value,
			unit: v.unit
		} }));
	}, [dispatch]);
	const setPayoutAddress = useCallback((addressType, value) => dispatch(actions.setPayoutAddress({
		addressType,
		value
	})), [dispatch]);
	const setPaymentTerm = useCallback((paymentTerm) => paymentTerm && dispatch(actions.setPaymentTerm({ paymentTerm })), [dispatch]);
	const recordPayout = useCallback((payoutType, value, proof) => dispatch(actions.recordPayout({
		id: generateId(),
		payoutType,
		value,
		proof: proof || null,
		timestamp: (/* @__PURE__ */ new Date()).toISOString()
	})), [dispatch]);
	const markCompleted = useCallback(() => dispatch(actions.markCompleted({ completedAt: (/* @__PURE__ */ new Date()).toISOString() })), [dispatch]);
	const setExtensions = useCallback((extensions) => dispatch(actions.setAppExtensions({ extensions })), [dispatch]);
	const submit = useCallback((identifier) => dispatch(actions.submitApplication({
		submittedAt: (/* @__PURE__ */ new Date()).toISOString(),
		submitterType: "COMMUNITY",
		identifier
	})), [dispatch]);
	const markRevised = useCallback(() => dispatch(actions.markRevised({ revisedAt: (/* @__PURE__ */ new Date()).toISOString() })), [dispatch]);
	const withdraw = useCallback((reason) => dispatch(actions.withdrawApplication({
		withdrawnAt: (/* @__PURE__ */ new Date()).toISOString(),
		reason
	})), [dispatch]);
	const openApplication = useCallback(() => dispatch(actions.openApplication({ openedAt: (/* @__PURE__ */ new Date()).toISOString() })), [dispatch]);
	const startReview = useCallback((reviewerDid) => dispatch(actions.startReview({
		reviewerDid,
		startedAt: (/* @__PURE__ */ new Date()).toISOString()
	})), [dispatch]);
	const requestRevision = useCallback((feedbackNotes) => dispatch(actions.requestRevision({
		feedbackNotes,
		requestedAt: (/* @__PURE__ */ new Date()).toISOString()
	})), [dispatch]);
	const approve = useCallback((reviewerDid) => dispatch(actions.approveApplication({
		approvedAt: (/* @__PURE__ */ new Date()).toISOString(),
		reviewerDid
	})), [dispatch]);
	const conditionallyApprove = useCallback((reviewerDid, conditions) => dispatch(actions.conditionallyApprove({
		approvedAt: (/* @__PURE__ */ new Date()).toISOString(),
		reviewerDid,
		conditions
	})), [dispatch]);
	const reject = useCallback((reviewerDid, reason) => dispatch(actions.rejectApplication({
		rejectedAt: (/* @__PURE__ */ new Date()).toISOString(),
		reviewerDid,
		reason
	})), [dispatch]);
	if (!document) return null;
	const state = document.state.global;
	return /* @__PURE__ */ jsxs("div", {
		className: "rfp-scope",
		children: [/* @__PURE__ */ jsx(DocumentToolbar, {}), /* @__PURE__ */ jsx("div", {
			className: "rfp-page",
			children: /* @__PURE__ */ jsxs("div", {
				className: "rfp-page-inner",
				children: [
					/* @__PURE__ */ jsx(ApplicationHeader, { state }),
					state.feedbackNotes ? /* @__PURE__ */ jsx(ReviewerFeedbackCard, { feedback: state.feedbackNotes }) : null,
					/* @__PURE__ */ jsx(ApplicationMeta, {
						state,
						on: {
							setLicenseUri,
							setIsInactive,
							setCompletionRate
						}
					}),
					/* @__PURE__ */ jsx(ApplicationContent, {
						state,
						on: {
							setContent,
							setDiscussions
						}
					}),
					/* @__PURE__ */ jsx(ApplicationSocials, {
						state,
						on: {
							addSocial,
							removeSocial
						}
					}),
					/* @__PURE__ */ jsx(ApplicationFunding, {
						state,
						on: {
							addFundsAsked,
							removeFundsAsked,
							setFundsAskedUsd,
							addFundsApproved,
							setFundsApprovedUsd,
							setPayoutAddress,
							setPaymentTerm
						}
					}),
					/* @__PURE__ */ jsx(ApplicantActions, {
						state,
						on: {
							submit,
							markRevised,
							withdraw
						}
					}),
					/* @__PURE__ */ jsx(ReviewerActions, {
						state,
						on: {
							openApplication,
							startReview,
							requestRevision,
							approve,
							conditionallyApprove,
							reject
						}
					}),
					/* @__PURE__ */ jsx(ApplicationPayouts, {
						state,
						on: {
							recordPayout,
							markCompleted
						}
					}),
					/* @__PURE__ */ jsx(ApplicationExtensions, {
						state,
						on: { setExtensions }
					})
				]
			})
		})]
	});
}
//#endregion
export { Editor as default };

//# sourceMappingURL=editor-DQN5SYze.mjs.map