import { w as setName } from "./dist-uUUuTqM0.js";
import { a as setOperatorTeam, i as setOperationalHubName, r as removeSubteam, t as addSubteam } from "./creators-BZ72KijW.js";
import "./document-schema-DUJorxA0.js";
import { D as useParentFolderForSelectedNode, c as setSelectedNode, p as useDocumentById, x as useGetDocuments, y as useDrives } from "./dist-mx7YTOSV.js";
import "./chunk-VBDAOXYI-DjbP4DfS.js";
import { i as useSelectedOperationalHubProfileDocument } from "./hooks-BQaATsSq.js";
import { a as Users, i as setOpHubMemberOnBuilderProfile, n as setOpHubMember, o as ArrowLeft, r as useRemoteBuilderProfiles, s as PHIDInput } from "./builder-profile-wN6_wPAd.js";
import "./splitted-input-diff-kvHJ6NHp.js";
import { i as DocumentToolbar } from "./connect-MjNGHHUz-BfDIyhte.js";
import { t as Input } from "./input-9oyyJREH.js";
import { t as Pencil } from "./pencil-D2jMnnzZ.js";
import "./chunk-VBDAOXYI-BQc-Addq-Cd1mAaEz.js";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
//#region editors/operational-hub-profile-editor/components/SetOperatorTeam.tsx
/** Creates an icon element from an image URL */
function createIconElement(iconUrl) {
	if (!iconUrl) return void 0;
	return React.createElement("img", {
		src: iconUrl,
		alt: "",
		style: {
			width: 24,
			height: 24,
			borderRadius: 4,
			objectFit: "cover"
		}
	});
}
function SetOperatorTeam({ operatorTeam, dispatch, opHubPhid, opHubName }) {
	const drives = useDrives();
	const getDocuments = useGetDocuments();
	const [pendingOpHubUpdate, setPendingOpHubUpdate] = useState(null);
	const [pendingDoc, pendingDispatch] = useDocumentById(pendingOpHubUpdate?.phid);
	useEffect(() => {
		if (pendingOpHubUpdate && pendingDoc && pendingDispatch) {
			pendingDispatch(setOpHubMember({
				name: pendingOpHubUpdate.name,
				phid: pendingOpHubUpdate.opHubPhid
			}));
			setPendingOpHubUpdate(null);
		}
	}, [
		pendingOpHubUpdate,
		pendingDoc,
		pendingDispatch
	]);
	const localProfileNodes = useMemo(() => {
		if (!drives) return [];
		return drives.filter((drive) => drive.header.documentType === "powerhouse/document-drive").flatMap((drive) => drive.state.global.nodes.filter((node) => node.kind === "file" && "documentType" in node && node.documentType === "powerhouse/builder-profile").map((node) => ({
			id: node.id,
			name: node.name || "Untitled builder",
			driveName: drive.state.global.name || drive.header.id
		})));
	}, [drives]);
	const localProfilePhids = useMemo(() => localProfileNodes.map((node) => node.id), [localProfileNodes]);
	const [localProfileDocuments, setLocalProfileDocuments] = useState([]);
	useEffect(() => {
		if (localProfilePhids.length === 0) {
			setLocalProfileDocuments([]);
			return;
		}
		getDocuments(localProfilePhids).then((docs) => {
			setLocalProfileDocuments(docs);
		}).catch((error) => {
			console.error("Failed to fetch builder profile documents:", error);
			setLocalProfileDocuments([]);
		});
	}, [localProfilePhids, getDocuments]);
	const localProfileStateMap = useMemo(() => {
		const map = /* @__PURE__ */ new Map();
		for (const doc of localProfileDocuments) {
			const state = doc.state?.global;
			if (state) map.set(doc.header.id, state);
		}
		return map;
	}, [localProfileDocuments]);
	const localBuilderProfiles = useMemo(() => {
		return localProfileNodes.map((node) => {
			const state = localProfileStateMap.get(node.id);
			const name = state?.name || node.name;
			return {
				id: node.id,
				label: name,
				value: node.id,
				title: name,
				path: node.driveName,
				description: state?.description || void 0,
				icon: createIconElement(state?.icon)
			};
		});
	}, [localProfileNodes, localProfileStateMap]);
	const { allProfiles: remoteProfiles, isLoading: isLoadingRemote } = useRemoteBuilderProfiles(useMemo(() => {
		const map = /* @__PURE__ */ new Map();
		localBuilderProfiles.forEach((profile) => {
			map.set(profile.id, profile);
		});
		return map;
	}, [localBuilderProfiles]));
	const builderProfileOptions = useMemo(() => {
		const options = [...localBuilderProfiles];
		for (const remoteProfile of remoteProfiles) {
			const name = remoteProfile.state.name || remoteProfile.id;
			options.push({
				id: remoteProfile.id,
				label: name,
				value: remoteProfile.id,
				title: name,
				path: "Remote",
				description: remoteProfile.state.description || void 0,
				icon: createIconElement(remoteProfile.state.icon)
			});
		}
		return options;
	}, [localBuilderProfiles, remoteProfiles]);
	const isKnownPhid = useCallback((phid) => builderProfileOptions.some((opt) => opt.value === phid), [builderProfileOptions]);
	const isLocalProfile = useCallback((phid) => localProfilePhids.includes(phid), [localProfilePhids]);
	const handleSave = useCallback(async (phid) => {
		if (phid !== operatorTeam) {
			dispatch(setOperatorTeam({ operatorTeam: phid || null }));
			if (phid) {
				if (isLocalProfile(phid)) setPendingOpHubUpdate({
					phid,
					name: opHubName || null,
					opHubPhid
				});
				try {
					await setOpHubMemberOnBuilderProfile(phid, {
						name: opHubName || null,
						phid: opHubPhid
					});
				} catch (error) {
					console.error("Failed to set op hub member on builder profile (remote):", error);
				}
			}
		}
	}, [
		dispatch,
		operatorTeam,
		opHubPhid,
		opHubName,
		isLocalProfile
	]);
	const handleClear = useCallback(async () => {
		if (operatorTeam) {
			dispatch(setOperatorTeam({ operatorTeam: null }));
			if (isLocalProfile(operatorTeam)) setPendingOpHubUpdate({
				phid: operatorTeam,
				name: null,
				opHubPhid: null
			});
			try {
				await setOpHubMemberOnBuilderProfile(operatorTeam, {
					name: null,
					phid: null
				});
			} catch (error) {
				console.error("Failed to clear op hub member on builder profile (remote):", error);
			}
		}
	}, [
		dispatch,
		operatorTeam,
		isLocalProfile
	]);
	const fetchOptionsCallback = useCallback((input) => {
		const normalizedInput = input.toLowerCase().trim();
		if (!normalizedInput) return Promise.resolve(builderProfileOptions.slice(0, 10));
		return Promise.resolve(builderProfileOptions.filter((opt) => opt.label.toLowerCase().includes(normalizedInput) || opt.value.toLowerCase().includes(normalizedInput) || opt.path?.toLowerCase().includes(normalizedInput) || opt.description?.toLowerCase().includes(normalizedInput)));
	}, [builderProfileOptions]);
	return /* @__PURE__ */ jsx(PHIDInput, {
		value: operatorTeam || "",
		onChange: (newValue) => {
			if (!newValue || newValue === "") handleClear();
			else if (isKnownPhid(newValue)) handleSave(newValue);
		},
		onBlur: () => {},
		placeholder: isLoadingRemote ? "Loading profiles..." : "Search builder name or enter PHID",
		className: "w-full",
		variant: "withValueTitleAndDescription",
		initialOptions: builderProfileOptions,
		fetchOptionsCallback
	});
}
//#endregion
//#region editors/operational-hub-profile-editor/components/SubteamsPicker.tsx
function SubteamsPicker({ subteams, operatorTeam, dispatch, opHubPhid, opHubName }) {
	const drives = useDrives();
	const [query, setQuery] = useState("");
	const [isPickerOpen, setIsPickerOpen] = useState(false);
	const pickerRef = useRef(null);
	const [pendingOpHubUpdate, setPendingOpHubUpdate] = useState(null);
	const [pendingDoc, pendingDispatch] = useDocumentById(pendingOpHubUpdate?.phid);
	useEffect(() => {
		if (pendingOpHubUpdate && pendingDoc && pendingDispatch) {
			pendingDispatch(setOpHubMember({
				name: pendingOpHubUpdate.name,
				phid: pendingOpHubUpdate.opHubPhid
			}));
			setPendingOpHubUpdate(null);
		}
	}, [
		pendingOpHubUpdate,
		pendingDoc,
		pendingDispatch
	]);
	const getDocuments = useGetDocuments();
	const localProfileNodes = useMemo(() => {
		if (!drives) return [];
		return drives.filter((drive) => drive.header.documentType === "powerhouse/document-drive").flatMap((drive) => drive.state.global.nodes.filter((node) => node.kind === "file" && "documentType" in node && node.documentType === "powerhouse/builder-profile").map((node) => ({
			id: node.id,
			name: node.name || "Untitled builder",
			driveId: drive.header.id
		})));
	}, [drives]);
	const localProfilePhids = useMemo(() => localProfileNodes.map((node) => node.id), [localProfileNodes]);
	const [localProfileDocuments, setLocalProfileDocuments] = useState([]);
	useEffect(() => {
		if (localProfilePhids.length === 0) {
			setLocalProfileDocuments([]);
			return;
		}
		getDocuments(localProfilePhids).then((docs) => {
			setLocalProfileDocuments(docs);
		}).catch((error) => {
			console.error("Failed to fetch builder profile documents:", error);
			setLocalProfileDocuments([]);
		});
	}, [localProfilePhids, getDocuments]);
	const localProfileStateMap = useMemo(() => {
		const map = /* @__PURE__ */ new Map();
		for (const doc of localProfileDocuments) {
			const state = doc.state?.global;
			if (state) map.set(doc.header.id, state);
		}
		return map;
	}, [localProfileDocuments]);
	const localBuilderProfiles = useMemo(() => {
		return localProfileNodes.map((node) => {
			const state = localProfileStateMap.get(node.id);
			return {
				id: node.id,
				name: state?.name || node.name,
				driveId: node.driveId,
				isRemote: false
			};
		});
	}, [localProfileNodes, localProfileStateMap]);
	const { allProfiles: remoteProfiles, isLoading: isLoadingRemote } = useRemoteBuilderProfiles(useMemo(() => {
		const map = /* @__PURE__ */ new Map();
		localBuilderProfiles.forEach((profile) => {
			map.set(profile.id, profile);
		});
		return map;
	}, [localBuilderProfiles]));
	const builderProfiles = useMemo(() => {
		const profiles = [...localBuilderProfiles];
		for (const remoteProfile of remoteProfiles) profiles.push({
			id: remoteProfile.id,
			name: remoteProfile.state.name || remoteProfile.id,
			driveId: "remote",
			isRemote: true
		});
		return profiles;
	}, [localBuilderProfiles, remoteProfiles]);
	const subteamIdSet = new Set(subteams);
	const availableProfiles = builderProfiles.filter((profile) => !subteamIdSet.has(profile.id));
	const normalizedQuery = query.trim().toLowerCase();
	const filteredProfiles = normalizedQuery ? availableProfiles.filter((profile) => profile.name.toLowerCase().includes(normalizedQuery)) : availableProfiles.slice(0, 5);
	const localProfileIds = useMemo(() => localBuilderProfiles.map((p) => p.id), [localBuilderProfiles]);
	const isLocalProfile = useCallback((phid) => localProfileIds.includes(phid), [localProfileIds]);
	const updateBuilderProfileOpHub = useCallback(async (builderProfilePhid) => {
		if (isLocalProfile(builderProfilePhid)) setPendingOpHubUpdate({
			phid: builderProfilePhid,
			name: opHubName || null,
			opHubPhid
		});
		try {
			await setOpHubMemberOnBuilderProfile(builderProfilePhid, {
				name: opHubName || null,
				phid: opHubPhid
			});
		} catch (error) {
			console.error("Failed to set op hub member on builder profile (remote):", error);
		}
	}, [
		opHubPhid,
		opHubName,
		isLocalProfile
	]);
	const handleSelect = useCallback((profile) => {
		dispatch(addSubteam({ subteam: profile.id }));
		updateBuilderProfileOpHub(profile.id);
		setQuery("");
		setIsPickerOpen(false);
	}, [dispatch, updateBuilderProfileOpHub]);
	const handleManualSelect = useCallback((value) => {
		const trimmed = value.trim();
		if (!trimmed || subteamIdSet.has(trimmed)) return;
		dispatch(addSubteam({ subteam: trimmed }));
		updateBuilderProfileOpHub(trimmed);
		setQuery("");
		setIsPickerOpen(false);
	}, [
		dispatch,
		subteamIdSet,
		updateBuilderProfileOpHub
	]);
	const handleRemoveSubteam = (subteamId) => {
		dispatch(removeSubteam({ subteam: subteamId }));
	};
	useEffect(() => {
		if (!isPickerOpen) return;
		const handleClickOutside = (event) => {
			if (pickerRef.current && event.target instanceof Node && !pickerRef.current.contains(event.target)) setIsPickerOpen(false);
		};
		document.addEventListener("mousedown", handleClickOutside);
		return () => document.removeEventListener("mousedown", handleClickOutside);
	}, [isPickerOpen]);
	return /* @__PURE__ */ jsxs("div", {
		className: "space-y-3",
		children: [subteams.length > 0 && /* @__PURE__ */ jsx("div", {
			className: "space-y-2",
			children: subteams.map((subteamId) => /* @__PURE__ */ jsx(SubteamCard$1, {
				subteamId,
				builderProfiles,
				onRemove: () => handleRemoveSubteam(subteamId)
			}, subteamId))
		}), /* @__PURE__ */ jsxs("div", {
			className: "relative",
			ref: pickerRef,
			children: [/* @__PURE__ */ jsx("div", {
				className: "flex items-center gap-2",
				children: /* @__PURE__ */ jsx("input", {
					type: "text",
					value: query,
					onChange: (event) => setQuery(event.target.value),
					onFocus: () => setIsPickerOpen(true),
					placeholder: isLoadingRemote ? "Loading profiles..." : subteams.length === 0 ? "Search builder name to add subteam..." : "Add another subteam...",
					className: "flex-1 min-w-[280px] rounded-md border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 shadow-sm focus:border-gray-500 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-100 dark:focus:border-gray-400 dark:focus:ring-gray-800"
				})
			}), isPickerOpen && /* @__PURE__ */ jsx("div", {
				className: "absolute z-10 mt-2 w-full max-h-64 overflow-auto rounded-md border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-900",
				children: filteredProfiles.length > 0 ? filteredProfiles.map((profile) => {
					const isOperatorTeam = operatorTeam === profile.id;
					return /* @__PURE__ */ jsxs("button", {
						type: "button",
						onClick: () => !isOperatorTeam && handleSelect(profile),
						disabled: isOperatorTeam,
						className: `flex w-full flex-col px-3 py-2 text-left text-sm ${isOperatorTeam ? "cursor-not-allowed bg-gray-50 text-gray-400 dark:bg-gray-800 dark:text-gray-500" : "text-gray-900 hover:bg-gray-50 dark:text-gray-100 dark:hover:bg-gray-800"}`,
						children: [/* @__PURE__ */ jsxs("span", {
							className: "font-medium",
							children: [
								profile.name,
								profile.isRemote && /* @__PURE__ */ jsx("span", {
									className: "ml-2 text-xs text-blue-500 dark:text-blue-400",
									children: "(remote)"
								}),
								isOperatorTeam && /* @__PURE__ */ jsx("span", {
									className: "ml-2 text-xs text-amber-600 dark:text-amber-400",
									children: "(already set as Operator Team)"
								})
							]
						}), /* @__PURE__ */ jsx("span", {
							className: "text-xs text-gray-500 dark:text-gray-400",
							children: profile.id
						})]
					}, `${profile.driveId}-${profile.id}`);
				}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
					className: "px-3 py-2 text-sm text-gray-500 dark:text-gray-400",
					children: normalizedQuery ? "No matching teams" : "No more teams available"
				}), normalizedQuery && !subteamIdSet.has(normalizedQuery) && /* @__PURE__ */ jsxs("button", {
					type: "button",
					onClick: () => handleManualSelect(query),
					className: "flex w-full flex-col px-3 py-2 text-left text-sm text-gray-900 hover:bg-gray-50 dark:text-gray-100 dark:hover:bg-gray-800",
					children: [/* @__PURE__ */ jsx("span", {
						className: "font-medium",
						children: "Use this ID"
					}), /* @__PURE__ */ jsx("span", {
						className: "text-xs text-gray-500 dark:text-gray-400",
						children: query
					})]
				})] })
			})]
		})]
	});
}
function SubteamCard$1({ subteamId, builderProfiles, onRemove }) {
	const profile = builderProfiles.find((p) => p.id === subteamId);
	return /* @__PURE__ */ jsx("div", {
		className: "rounded-md border border-gray-200 bg-white px-3 py-2 shadow-sm dark:border-gray-700 dark:bg-gray-900",
		children: /* @__PURE__ */ jsxs("div", {
			className: "flex items-start justify-between gap-2",
			children: [/* @__PURE__ */ jsxs("div", {
				className: "flex-1 min-w-0",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "text-sm font-semibold text-gray-900 dark:text-gray-100",
					children: [profile?.name || "Unknown team", profile?.isRemote && /* @__PURE__ */ jsx("span", {
						className: "ml-2 text-xs font-normal text-blue-500 dark:text-blue-400",
						children: "(remote)"
					})]
				}), /* @__PURE__ */ jsx("div", {
					className: "mt-1 text-xs font-mono text-gray-500 dark:text-gray-400 truncate",
					children: subteamId
				})]
			}), /* @__PURE__ */ jsx("button", {
				type: "button",
				onClick: onRemove,
				className: "p-1 text-gray-400 hover:text-red-500 dark:text-gray-500 dark:hover:text-red-400",
				title: "Remove subteam",
				children: /* @__PURE__ */ jsx("svg", {
					className: "w-4 h-4",
					fill: "none",
					stroke: "currentColor",
					viewBox: "0 0 24 24",
					children: /* @__PURE__ */ jsx("path", {
						strokeLinecap: "round",
						strokeLinejoin: "round",
						strokeWidth: 2,
						d: "M6 18L18 6M6 6l12 12"
					})
				})
			})]
		})
	});
}
//#endregion
//#region editors/operational-hub-profile-editor/components/ProfileOverview.tsx
const MAX_VISIBLE_SUBTEAMS = 6;
function ProfileOverview({ name, operatorTeam, subteams, onEdit }) {
	const drives = useDrives();
	const builderProfileNodes = useMemo(() => {
		if (!drives) return [];
		return drives.flatMap((drive) => {
			return drive.state.global.nodes.filter((node) => node.kind === "file" && "documentType" in node && node.documentType === "powerhouse/builder-profile").map((node) => ({
				node,
				driveId: drive.header.id
			}));
		});
	}, [drives]);
	const builderPhids = useMemo(() => builderProfileNodes.map(({ node }) => node.id), [builderProfileNodes]);
	const getDocuments = useGetDocuments();
	const [builderProfileDocuments, setBuilderProfileDocuments] = useState([]);
	useEffect(() => {
		if (builderPhids.length === 0) {
			setBuilderProfileDocuments([]);
			return;
		}
		getDocuments(builderPhids).then((docs) => setBuilderProfileDocuments(docs)).catch((error) => {
			console.error("Failed to fetch builder profile documents:", error);
			setBuilderProfileDocuments([]);
		});
	}, [builderPhids, getDocuments]);
	const localBuilderProfileMap = useMemo(() => {
		const map = /* @__PURE__ */ new Map();
		for (const doc of builderProfileDocuments) if (doc?.header?.documentType === "powerhouse/builder-profile") map.set(doc.header.id, doc);
		return map;
	}, [builderProfileDocuments]);
	const { profileMap: remoteProfileMap } = useRemoteBuilderProfiles(localBuilderProfileMap);
	const getBuilderProfileByPhid = useCallback((phid) => {
		const localDoc = localBuilderProfileMap.get(phid);
		if (localDoc) return {
			phid,
			name: localDoc.state.global.name || "Unknown",
			icon: localDoc.state.global.icon || null
		};
		const remoteProfile = remoteProfileMap.get(phid);
		if (remoteProfile) return {
			phid,
			name: remoteProfile.state?.name || "Unknown",
			icon: remoteProfile.state?.icon || null
		};
		return null;
	}, [localBuilderProfileMap, remoteProfileMap]);
	const operatorProfile = useMemo(() => {
		if (!operatorTeam) return null;
		return getBuilderProfileByPhid(operatorTeam);
	}, [operatorTeam, getBuilderProfileByPhid]);
	const subteamProfiles = useMemo(() => {
		return subteams.map((phid) => getBuilderProfileByPhid(phid)).filter((p) => p !== null);
	}, [subteams, getBuilderProfileByPhid]);
	const [isExpanded, setIsExpanded] = useState(false);
	const hasOverflow = subteams.length > MAX_VISIBLE_SUBTEAMS;
	const visibleSubteams = isExpanded ? subteamProfiles : subteamProfiles.slice(0, MAX_VISIBLE_SUBTEAMS);
	return /* @__PURE__ */ jsxs("div", {
		className: "space-y-6",
		children: [
			/* @__PURE__ */ jsxs("div", {
				className: "flex items-center justify-between",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "flex items-center gap-3",
					children: [/* @__PURE__ */ jsx("span", {
						className: "flex items-center justify-center w-10 h-10 rounded-lg bg-purple-800 flex-shrink-0",
						children: /* @__PURE__ */ jsx("svg", {
							xmlns: "http://www.w3.org/2000/svg",
							width: "20",
							height: "20",
							viewBox: "0 0 24 24",
							fill: "none",
							stroke: "currentColor",
							strokeWidth: "2",
							strokeLinecap: "round",
							strokeLinejoin: "round",
							className: "text-white",
							children: /* @__PURE__ */ jsx("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" })
						})
					}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h1", {
						className: "text-2xl font-bold text-gray-900 dark:text-white",
						children: name
					}), /* @__PURE__ */ jsx("p", {
						className: "text-sm text-gray-500 dark:text-gray-400",
						children: "Operational Hub Profile"
					})] })]
				}), /* @__PURE__ */ jsxs("button", {
					type: "button",
					onClick: onEdit,
					className: "inline-flex items-center gap-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-200 shadow-sm hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors",
					children: [/* @__PURE__ */ jsx(Pencil, { className: "w-4 h-4" }), "Edit Profile"]
				})]
			}),
			/* @__PURE__ */ jsxs("section", {
				className: "bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-5",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "flex items-center gap-2 mb-4",
					children: [/* @__PURE__ */ jsx(Users, { className: "w-5 h-5 text-gray-500 dark:text-gray-400" }), /* @__PURE__ */ jsx("h2", {
						className: "text-lg font-semibold text-gray-900 dark:text-white",
						children: "Operator Team"
					})]
				}), operatorTeam ? /* @__PURE__ */ jsxs("div", {
					className: "flex items-center gap-3",
					children: [/* @__PURE__ */ jsx(ProfileAvatar, {
						name: operatorProfile?.name || "Unknown",
						icon: operatorProfile?.icon || null,
						size: "md"
					}), /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
						className: "font-medium text-gray-900 dark:text-white",
						children: operatorProfile?.name || "Unknown"
					}), /* @__PURE__ */ jsx("p", {
						className: "text-xs font-mono text-gray-400 dark:text-gray-500",
						children: operatorTeam
					})] })]
				}) : /* @__PURE__ */ jsx("p", {
					className: "text-sm text-gray-400 dark:text-gray-500 italic",
					children: "No operator team assigned"
				})]
			}),
			/* @__PURE__ */ jsxs("section", {
				className: "bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-5",
				children: [/* @__PURE__ */ jsxs("div", {
					className: "flex items-center gap-3 mb-4",
					children: [/* @__PURE__ */ jsx("h2", {
						className: "text-lg font-semibold text-gray-900 dark:text-white",
						children: "Subteams"
					}), /* @__PURE__ */ jsx("span", {
						className: "inline-flex items-center justify-center rounded-full bg-indigo-100 dark:bg-indigo-900 px-2.5 py-0.5 text-sm font-medium text-indigo-700 dark:text-indigo-300",
						children: subteams.length
					})]
				}), subteams.length > 0 ? /* @__PURE__ */ jsxs("div", {
					className: "flex flex-wrap gap-4",
					children: [
						visibleSubteams.map((profile) => /* @__PURE__ */ jsx(SubteamCard, { profile }, profile.phid)),
						hasOverflow && !isExpanded && /* @__PURE__ */ jsxs("button", {
							type: "button",
							onClick: () => setIsExpanded(true),
							className: "flex flex-col items-center gap-2 group cursor-pointer",
							title: "Click to show all subteams",
							children: [/* @__PURE__ */ jsx("div", {
								className: "flex h-14 w-14 items-center justify-center rounded-full bg-slate-100 ring-2 ring-white shadow-sm transition-all group-hover:bg-indigo-100 group-hover:ring-indigo-200",
								children: /* @__PURE__ */ jsxs("span", {
									className: "text-sm font-semibold text-slate-500 group-hover:text-indigo-600",
									children: ["+", subteams.length - MAX_VISIBLE_SUBTEAMS]
								})
							}), /* @__PURE__ */ jsx("span", {
								className: "text-xs font-medium text-slate-400 group-hover:text-indigo-500",
								children: "show all"
							})]
						}),
						hasOverflow && isExpanded && /* @__PURE__ */ jsxs("button", {
							type: "button",
							onClick: () => setIsExpanded(false),
							className: "flex flex-col items-center gap-2 group cursor-pointer",
							title: "Click to show less",
							children: [/* @__PURE__ */ jsx("div", {
								className: "flex h-14 w-14 items-center justify-center rounded-full bg-slate-100 ring-2 ring-white shadow-sm transition-all group-hover:bg-slate-200",
								children: /* @__PURE__ */ jsx("svg", {
									className: "h-5 w-5 text-slate-500 group-hover:text-slate-700",
									fill: "none",
									viewBox: "0 0 24 24",
									stroke: "currentColor",
									strokeWidth: 2,
									children: /* @__PURE__ */ jsx("path", {
										strokeLinecap: "round",
										strokeLinejoin: "round",
										d: "M5 15l7-7 7 7"
									})
								})
							}), /* @__PURE__ */ jsx("span", {
								className: "text-xs font-medium text-slate-400 group-hover:text-slate-600",
								children: "show less"
							})]
						})
					]
				}) : /* @__PURE__ */ jsxs("div", {
					className: "rounded-xl border border-dashed border-slate-300 dark:border-slate-600 bg-slate-50/50 dark:bg-slate-800/50 p-8 text-center",
					children: [/* @__PURE__ */ jsx("div", {
						className: "mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-slate-100 dark:bg-slate-700",
						children: /* @__PURE__ */ jsx(Users, { className: "h-6 w-6 text-slate-400" })
					}), /* @__PURE__ */ jsx("p", {
						className: "text-sm text-slate-500 dark:text-slate-400",
						children: "No subteams added yet."
					})]
				})]
			})
		]
	});
}
function SubteamCard({ profile }) {
	const initials = profile.name.split(" ").map((word) => word[0]).join("").slice(0, 2).toUpperCase();
	return /* @__PURE__ */ jsxs("div", {
		className: "group flex flex-col items-center gap-2",
		children: [/* @__PURE__ */ jsxs("div", {
			className: "relative",
			children: [profile.icon ? /* @__PURE__ */ jsx("img", {
				src: profile.icon,
				alt: profile.name,
				className: "h-14 w-14 rounded-full object-cover ring-2 ring-white shadow-md transition-transform group-hover:scale-105",
				onError: (e) => {
					e.currentTarget.style.display = "none";
					const fallback = e.currentTarget.nextElementSibling;
					if (fallback) fallback.style.display = "flex";
				}
			}) : null, /* @__PURE__ */ jsx("div", {
				className: `h-14 w-14 rounded-full bg-gradient-to-br from-slate-400 to-slate-500 ring-2 ring-white shadow-md ${profile.icon ? "hidden" : "flex"} items-center justify-center transition-transform group-hover:scale-105`,
				children: /* @__PURE__ */ jsx("span", {
					className: "text-sm font-semibold text-white",
					children: initials
				})
			})]
		}), /* @__PURE__ */ jsx("span", {
			className: "max-w-[80px] truncate text-xs font-medium text-slate-600 dark:text-slate-400",
			children: profile.name
		})]
	});
}
function ProfileAvatar({ name, icon, size = "md" }) {
	const initials = name.split(" ").map((word) => word[0]).join("").slice(0, 2).toUpperCase();
	const sizeClass = size === "sm" ? "h-10 w-10" : "h-12 w-12";
	const textSize = size === "sm" ? "text-xs" : "text-sm";
	return /* @__PURE__ */ jsxs("div", {
		className: "relative",
		children: [icon ? /* @__PURE__ */ jsx("img", {
			src: icon,
			alt: name,
			className: `${sizeClass} rounded-full object-cover ring-2 ring-white shadow-md`,
			onError: (e) => {
				e.currentTarget.style.display = "none";
				const fallback = e.currentTarget.nextElementSibling;
				if (fallback) fallback.style.display = "flex";
			}
		}) : null, /* @__PURE__ */ jsx("div", {
			className: `${sizeClass} rounded-full bg-gradient-to-br from-purple-400 to-purple-600 ring-2 ring-white shadow-md ${icon ? "hidden" : "flex"} items-center justify-center`,
			children: /* @__PURE__ */ jsx("span", {
				className: `${textSize} font-semibold text-white`,
				children: initials
			})
		})]
	});
}
//#endregion
//#region editors/operational-hub-profile-editor/editor.tsx
function Editor() {
	const [document, dispatch] = useSelectedOperationalHubProfileDocument();
	const parentFolder = useParentFolderForSelectedNode();
	const [mode, setMode] = useState("overview");
	const [localName, setLocalName] = useState("");
	useEffect(() => {
		if (document) setLocalName(document.state.global.name || "");
	}, [document?.state.global.name]);
	if (!document || !dispatch) return /* @__PURE__ */ jsx("div", { children: "Loading..." });
	const { name, operatorTeam, subteams } = document.state.global;
	const isConfigured = Boolean(name?.trim());
	const showOverview = isConfigured && mode === "overview";
	const handleNameBlur = () => {
		const trimmedName = localName.trim();
		if (trimmedName !== document.state.global.name) {
			dispatch(setOperationalHubName({ name: trimmedName }));
			dispatch(setName(trimmedName));
		}
	};
	function handleClose() {
		setSelectedNode(parentFolder?.id);
	}
	return /* @__PURE__ */ jsxs("div", {
		className: "h-screen flex flex-col bg-gray-50 dark:bg-gray-900",
		children: [/* @__PURE__ */ jsx(DocumentToolbar, {
			document,
			onClose: handleClose
		}), /* @__PURE__ */ jsx("div", {
			className: "flex-1 overflow-auto",
			children: showOverview ? /* @__PURE__ */ jsx("div", {
				className: "max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8",
				children: /* @__PURE__ */ jsx(ProfileOverview, {
					name,
					operatorTeam,
					subteams,
					onEdit: () => setMode("edit")
				})
			}) : /* @__PURE__ */ jsxs("div", {
				className: "max-w-2xl mx-auto px-4 sm:px-6 lg:px-8 py-8 space-y-6",
				children: [
					isConfigured && /* @__PURE__ */ jsxs("button", {
						type: "button",
						onClick: () => setMode("overview"),
						className: "inline-flex items-center gap-1.5 text-sm font-medium text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 transition-colors",
						children: [/* @__PURE__ */ jsx(ArrowLeft, { className: "w-4 h-4" }), "Back to Overview"]
					}),
					/* @__PURE__ */ jsx("section", {
						className: "bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700",
						children: /* @__PURE__ */ jsxs("div", {
							className: "px-4 sm:px-6 py-4 sm:py-6",
							children: [
								/* @__PURE__ */ jsx("h1", {
									className: "text-xl sm:text-2xl lg:text-3xl font-bold text-gray-900 dark:text-white mb-6",
									children: "Operational Hub Profile"
								}),
								/* @__PURE__ */ jsxs("div", {
									className: "mb-6",
									children: [/* @__PURE__ */ jsx("label", {
										className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",
										children: "Hub Name"
									}), /* @__PURE__ */ jsx(Input, {
										type: "text",
										value: localName,
										onChange: (e) => setLocalName(e.target.value),
										onBlur: handleNameBlur,
										placeholder: "Enter hub name...",
										className: "w-full"
									})]
								}),
								/* @__PURE__ */ jsxs("div", { children: [
									/* @__PURE__ */ jsxs("label", {
										className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",
										children: [
											"Operator Team",
											" ",
											/* @__PURE__ */ jsx("span", {
												className: "text-gray-400 font-normal",
												children: "(optional)"
											})
										]
									}),
									/* @__PURE__ */ jsx(SetOperatorTeam, {
										operatorTeam,
										dispatch,
										opHubPhid: document.header.id,
										opHubName: document.state.global.name || ""
									}),
									/* @__PURE__ */ jsx("p", {
										className: "text-xs text-gray-500 dark:text-gray-400 mt-1",
										children: "Link to the builder team that operates this hub"
									})
								] })
							]
						})
					}),
					/* @__PURE__ */ jsxs("section", {
						className: "bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700",
						children: [/* @__PURE__ */ jsxs("div", {
							className: "px-4 sm:px-6 py-3 sm:py-4 border-b border-gray-200 dark:border-gray-700",
							children: [/* @__PURE__ */ jsxs("h2", {
								className: "text-lg sm:text-xl font-semibold text-gray-900 dark:text-white",
								children: [
									"Subteams",
									" ",
									/* @__PURE__ */ jsx("span", {
										className: "text-gray-400 font-normal text-base",
										children: "(optional)"
									})
								]
							}), /* @__PURE__ */ jsx("p", {
								className: "text-sm text-gray-500 dark:text-gray-400 mt-1",
								children: "Add builder teams that are managed by this operational hub"
							})]
						}), /* @__PURE__ */ jsx("div", {
							className: "p-4 sm:p-6",
							children: /* @__PURE__ */ jsx(SubteamsPicker, {
								subteams,
								operatorTeam,
								dispatch,
								opHubPhid: document.header.id,
								opHubName: document.state.global.name || ""
							})
						})]
					})
				]
			})
		})]
	});
}
//#endregion
export { Editor as default };

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