@kruschdev/pascal-plugin-plumbing 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,393 @@
1
+ /**
2
+ * `plumbing:pipe-run` — 3D Gravity-Sloped DWV, Vent Stack, Cold/Hot/Recirc Supply,
3
+ * Fuel Gas (IFGC), Condensate, and Rigid Dryer Vent Pipe Runs.
4
+ * Automatically renders 3D framing bore collars & steel nail plates at Bones stud/plate crossings!
5
+ * Render-safe module: zero `@pascal-app/editor` imports.
6
+ */
7
+
8
+ import {
9
+ BaseNode,
10
+ type FloorplanGeometry,
11
+ type GeometryContext,
12
+ type NodeDefinition,
13
+ type NodePort,
14
+ nodeType,
15
+ objectId,
16
+ } from '@pascal-app/core'
17
+ import { Box3, Group, Mesh, MeshStandardMaterial } from 'three'
18
+ import { z } from 'zod'
19
+ import { buildPipeRunCad } from '../cad/fittings'
20
+ import { systemColorMeta } from '../cad/materials'
21
+ import {
22
+ type SceneNodeLike,
23
+ computePipeFramingPenetrations,
24
+ extractBonesPlumbingContext,
25
+ resolveNodeLevelId,
26
+ } from '../ipc/framing-interop'
27
+ import { extractWallSegments } from '../ipc/routing'
28
+ import {
29
+ PIPE_NOMINAL_INCHES,
30
+ type PipeMaterial,
31
+ type PipeNominalSize,
32
+ type PlumbingSystem,
33
+ getPipeOuterDiameterM,
34
+ } from '../ipc/tables'
35
+ import { PipeNominalSizeEnum } from './fixture'
36
+
37
+ const Vec3Schema = z.tuple([z.number(), z.number(), z.number()])
38
+
39
+ export const PlumbingSystemEnum = z.enum([
40
+ 'cold-water',
41
+ 'hot-water',
42
+ 'hot-recirc',
43
+ 'dwv-drain',
44
+ 'dwv-vent',
45
+ 'fuel-gas',
46
+ 'condensate',
47
+ 'dryer-vent',
48
+ ])
49
+
50
+ export const PipeMaterialEnum = z.enum([
51
+ 'pex-a',
52
+ 'pex-b',
53
+ 'copper-l',
54
+ 'copper-m',
55
+ 'cpvc',
56
+ 'pvc-dwv',
57
+ 'abs-dwv',
58
+ 'cast-iron',
59
+ 'csst',
60
+ 'black-iron',
61
+ 'rigid-aluminum',
62
+ ])
63
+
64
+ export const PlumbingPipeRunNode = BaseNode.extend({
65
+ id: objectId('plumbpipe'),
66
+ type: nodeType('plumbing:pipe-run'),
67
+ path: z.array(Vec3Schema).min(2),
68
+ system: PlumbingSystemEnum.default('cold-water'),
69
+ material: PipeMaterialEnum.default('pex-a'),
70
+ nominalSize: PipeNominalSizeEnum.default('1/2"'),
71
+ slopeInPerFt: z.number().min(0).max(2).default(0),
72
+ dfuLoad: z.number().min(0).max(1000).default(0),
73
+ wsfuLoad: z.number().min(0).max(1000).default(0),
74
+ gasBtuh: z.number().min(0).max(2000000).default(0),
75
+ trapArmLengthFt: z.number().min(0).max(50).optional(),
76
+ sourceNodeId: z.string().optional(),
77
+ targetNodeId: z.string().optional(),
78
+ wallId: z.string().optional(),
79
+ hasCleanout: z.boolean().default(false),
80
+ hasSedimentTrap: z.boolean().default(true),
81
+ hasShutoffWithin6Ft: z.boolean().default(true),
82
+ isHorizontalSanTee: z.boolean().default(false),
83
+ isMainVentStack: z.boolean().default(false),
84
+ showFramingPenetrations: z.boolean().default(true),
85
+ /** When true, sub-slab / below-grade runs render through the opaque ground plane & floor slab (X-Ray Ground). */
86
+ xraySubSlab: z.boolean().default(false),
87
+ /** Optional revision token bumped when adjacent walls/framing change to invalidate cached 3D bore collars. */
88
+ framingRevision: z.number().int().min(0).optional(),
89
+ })
90
+
91
+ export type PlumbingPipeRunNode = z.infer<typeof PlumbingPipeRunNode>
92
+
93
+ function isFinitePt(p: unknown): p is [number, number, number] {
94
+ return (
95
+ Array.isArray(p) &&
96
+ p.length >= 3 &&
97
+ typeof p[0] === 'number' &&
98
+ typeof p[1] === 'number' &&
99
+ typeof p[2] === 'number' &&
100
+ Number.isFinite(p[0]) &&
101
+ Number.isFinite(p[1]) &&
102
+ Number.isFinite(p[2])
103
+ )
104
+ }
105
+
106
+ function normalizeDir(
107
+ a: readonly [number, number, number],
108
+ b: readonly [number, number, number],
109
+ sign: 1 | -1,
110
+ ): [number, number, number] {
111
+ const dx = (b[0] - a[0]) * sign
112
+ const dy = (b[1] - a[1]) * sign
113
+ const dz = (b[2] - a[2]) * sign
114
+ const len = Math.hypot(dx, dy, dz)
115
+ if (!Number.isFinite(len) || len < 1e-5) return [0, 1, 0]
116
+ return [dx / len, dy / len, dz / len]
117
+ }
118
+
119
+ export function getPlumbingPipeRunPorts(node: PlumbingPipeRunNode): NodePort[] {
120
+ const validPath = Array.isArray(node.path) ? node.path.filter(isFinitePt) : []
121
+ const start = validPath[0]
122
+ const end = validPath[validPath.length - 1]
123
+ if (!start || !end || validPath.length < 2) return []
124
+ let second = end
125
+ for (let i = 1; i < validPath.length; i++) {
126
+ const p = validPath[i]!
127
+ const len = Math.hypot(p[0] - start[0], p[1] - start[1], p[2] - start[2])
128
+ if (Number.isFinite(len) && len >= 1e-5) {
129
+ second = p
130
+ break
131
+ }
132
+ }
133
+ let prev = start
134
+ for (let i = validPath.length - 2; i >= 0; i--) {
135
+ const p = validPath[i]!
136
+ const len = Math.hypot(end[0] - p[0], end[1] - p[1], end[2] - p[2])
137
+ if (Number.isFinite(len) && len >= 1e-5) {
138
+ prev = p
139
+ break
140
+ }
141
+ }
142
+ const sys =
143
+ node.system.startsWith('dwv') || node.system === 'condensate'
144
+ ? 'dwv'
145
+ : node.system === 'fuel-gas'
146
+ ? 'gas'
147
+ : node.system === 'dryer-vent'
148
+ ? 'exhaust'
149
+ : 'water'
150
+ const diameter = PIPE_NOMINAL_INCHES[node.nominalSize as PipeNominalSize] ?? 1
151
+ return [
152
+ { id: 'start', position: start, direction: normalizeDir(start, second, -1), diameter, system: sys },
153
+ { id: 'end', position: end, direction: normalizeDir(prev, end, 1), diameter, system: sys },
154
+ ]
155
+ }
156
+
157
+ export function buildPlumbingPipeRunGeometry(
158
+ node: PlumbingPipeRunNode,
159
+ ctx: GeometryContext,
160
+ ): Group {
161
+ const validPath = Array.isArray(node.path) ? node.path.filter(isFinitePt) : []
162
+ let penetrations: ReturnType<typeof computePipeFramingPenetrations> = []
163
+ if (
164
+ validPath.length >= 2 &&
165
+ node.showFramingPenetrations &&
166
+ ctx &&
167
+ typeof ctx === 'object' &&
168
+ 'nodes' in ctx &&
169
+ ctx.nodes
170
+ ) {
171
+ const record = ctx.nodes as unknown as Readonly<Record<string, SceneNodeLike>>
172
+ const levelId = resolveNodeLevelId(record, node as unknown as SceneNodeLike) ?? node.parentId ?? null
173
+ const walls = extractWallSegments(record, levelId)
174
+ const bones = extractBonesPlumbingContext(record, levelId)
175
+ penetrations = computePipeFramingPenetrations({
176
+ pipeRunId: node.id,
177
+ path: validPath,
178
+ pipeSize: node.nominalSize as PipeNominalSize,
179
+ material: node.material as PipeMaterial,
180
+ walls,
181
+ bonesContext: bones,
182
+ })
183
+ }
184
+
185
+ const group = buildPipeRunCad({
186
+ id: node.id,
187
+ path: validPath,
188
+ system: node.system as PlumbingSystem,
189
+ material: node.material as PipeMaterial,
190
+ nominalSize: node.nominalSize as PipeNominalSize,
191
+ hasCleanout: node.hasCleanout,
192
+ penetrations,
193
+ })
194
+
195
+ // Sub-Slab X-Ray Ground Visibility: render ONLY below-grade pipe segments/fittings (maxY < 0.04 m)
196
+ // through Pascal's opaque y=0 ground plane and floor slab so above-grade risers & bore collars stay
197
+ // properly depth-tested behind opaque walls and cabinets.
198
+ const hasBelowGradePoint = validPath.some((p) => p[1] < -0.005)
199
+ if (node.xraySubSlab && hasBelowGradePoint && node.system !== 'dwv-vent') {
200
+ const isDarkDwv =
201
+ node.system === 'dwv-drain' && (node.material === 'abs-dwv' || node.material === 'cast-iron')
202
+ group.updateMatrixWorld(true)
203
+ const meshBox = new Box3()
204
+ const xrayCloneByBase = new Map<MeshStandardMaterial, MeshStandardMaterial>()
205
+ const getXrayClone = (base: MeshStandardMaterial): MeshStandardMaterial => {
206
+ let next = xrayCloneByBase.get(base)
207
+ if (!next) {
208
+ next = base.clone()
209
+ next.depthTest = false
210
+ next.depthWrite = false
211
+ next.transparent = true
212
+ next.opacity = 0.92
213
+ if (isDarkDwv) {
214
+ next.emissive.setHex(0x38bdf8)
215
+ next.emissiveIntensity = 0.28
216
+ }
217
+ next.needsUpdate = true
218
+ xrayCloneByBase.set(base, next)
219
+ }
220
+ return next
221
+ }
222
+ group.traverse((obj) => {
223
+ if (!(obj instanceof Mesh)) return
224
+ meshBox.setFromObject(obj)
225
+ if (!Number.isFinite(meshBox.max.y) || meshBox.max.y >= 0.04) return
226
+ obj.renderOrder = 30
227
+ if (Array.isArray(obj.material)) {
228
+ obj.material = obj.material.map((m) =>
229
+ m instanceof MeshStandardMaterial ? getXrayClone(m) : m,
230
+ )
231
+ } else if (obj.material instanceof MeshStandardMaterial) {
232
+ obj.material = getXrayClone(obj.material)
233
+ }
234
+ })
235
+ if (xrayCloneByBase.size > 0) {
236
+ const stillReferenced = new Set<unknown>()
237
+ group.traverse((obj) => {
238
+ if (!(obj instanceof Mesh)) return
239
+ if (Array.isArray(obj.material)) {
240
+ for (const m of obj.material) stillReferenced.add(m)
241
+ } else {
242
+ stillReferenced.add(obj.material)
243
+ }
244
+ })
245
+ for (const baseMat of xrayCloneByBase.keys()) {
246
+ if (!stillReferenced.has(baseMat)) {
247
+ baseMat.dispose()
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ return group
254
+ }
255
+
256
+ export function buildPlumbingPipeRunFloorplan(
257
+ node: PlumbingPipeRunNode,
258
+ ctx: GeometryContext,
259
+ ): FloorplanGeometry {
260
+ const view = ctx.viewState
261
+ const selected = (view?.selected || view?.highlighted) ?? false
262
+ const meta = systemColorMeta(node.system as PlumbingSystem)
263
+ const stroke = selected && view?.palette ? view.palette.selectedStroke : meta.hex
264
+ const children: FloorplanGeometry[] = []
265
+ const validPath = Array.isArray(node.path) ? node.path.filter(isFinitePt) : []
266
+
267
+ let drewHorizontal = false
268
+ for (let i = 0; i < validPath.length - 1; i++) {
269
+ const a = validPath[i]!
270
+ const b = validPath[i + 1]!
271
+ const len = Math.hypot(b[0] - a[0], b[2] - a[2])
272
+ if (!Number.isFinite(len) || len < 1e-3) continue
273
+ drewHorizontal = true
274
+ children.push({
275
+ kind: 'line',
276
+ x1: a[0],
277
+ y1: a[2],
278
+ x2: b[0],
279
+ y2: b[2],
280
+ stroke,
281
+ strokeWidth: selected ? 0.042 : node.system === 'dwv-drain' ? 0.032 : 0.022,
282
+ strokeDasharray: meta.dash2d ? '0.14 0.07' : undefined,
283
+ })
284
+ }
285
+
286
+ const start = validPath[0]
287
+ if (!drewHorizontal && start && validPath.length >= 2) {
288
+ // Pure vertical pipe stack (e.g., 3"/4" Main Vent Stack): render a visible 2D riser circle + crosshair
289
+ const odM = getPipeOuterDiameterM(node.nominalSize as PipeNominalSize, node.material as PipeMaterial)
290
+ const r = Math.max(0.085, (odM / 2) * 1.6)
291
+ const sw = selected ? 0.036 : 0.024
292
+ children.push(
293
+ {
294
+ kind: 'circle',
295
+ cx: start[0],
296
+ cy: start[2],
297
+ r,
298
+ fill: meta.hex,
299
+ fillOpacity: 0.22,
300
+ stroke,
301
+ strokeWidth: sw,
302
+ },
303
+ {
304
+ kind: 'line',
305
+ x1: start[0] - r * 0.85,
306
+ y1: start[2],
307
+ x2: start[0] + r * 0.85,
308
+ y2: start[2],
309
+ stroke,
310
+ strokeWidth: 0.018,
311
+ },
312
+ {
313
+ kind: 'line',
314
+ x1: start[0],
315
+ y1: start[2] - r * 0.85,
316
+ x2: start[0],
317
+ y2: start[2] + r * 0.85,
318
+ stroke,
319
+ strokeWidth: 0.018,
320
+ },
321
+ )
322
+ }
323
+
324
+ if (selected && start) {
325
+ children.push({ kind: 'move-handle', point: [start[0], start[2]] })
326
+ }
327
+ return { kind: 'group', children }
328
+ }
329
+
330
+ export const plumbingPipeRunRenderDefinition: NodeDefinition<typeof PlumbingPipeRunNode> = {
331
+ kind: 'plumbing:pipe-run',
332
+ schemaVersion: 1,
333
+ schema: PlumbingPipeRunNode,
334
+ category: 'utility',
335
+ distributionRole: 'run',
336
+ defaults: () => ({
337
+ object: 'node',
338
+ parentId: null,
339
+ visible: true,
340
+ metadata: {},
341
+ name: 'Pipe Run',
342
+ path: [
343
+ [0, 0.5, 0],
344
+ [1, 0.5, 0],
345
+ ],
346
+ system: 'cold-water',
347
+ material: 'pex-a',
348
+ nominalSize: '1/2"',
349
+ slopeInPerFt: 0,
350
+ dfuLoad: 0,
351
+ wsfuLoad: 0,
352
+ gasBtuh: 0,
353
+ hasCleanout: false,
354
+ hasSedimentTrap: true,
355
+ hasShutoffWithin6Ft: true,
356
+ isHorizontalSanTee: false,
357
+ isMainVentStack: false,
358
+ showFramingPenetrations: true,
359
+ xraySubSlab: false,
360
+ }),
361
+ capabilities: {
362
+ selectable: { hitVolume: 'bbox' },
363
+ duplicable: true,
364
+ deletable: true,
365
+ snappable: {},
366
+ },
367
+ geometry: buildPlumbingPipeRunGeometry,
368
+ geometryKey: (n) =>
369
+ JSON.stringify([
370
+ n.parentId ?? null,
371
+ n.path,
372
+ n.system,
373
+ n.material,
374
+ n.nominalSize,
375
+ n.hasCleanout,
376
+ n.showFramingPenetrations,
377
+ n.xraySubSlab ?? false,
378
+ n.wallId ?? null,
379
+ n.framingRevision ?? 0,
380
+ ]),
381
+ ports: getPlumbingPipeRunPorts,
382
+ floorplan: buildPlumbingPipeRunFloorplan,
383
+ presentation: {
384
+ label: 'Pipe Run',
385
+ description:
386
+ 'Gravity-sloped 3D DWV drain, vent stack, cold/hot/recirc supply, fuel gas, or rigid dryer vent run with framing bore collars.',
387
+ icon: { kind: 'iconify', name: 'lucide:git-branch' },
388
+ paletteSection: 'structure',
389
+ },
390
+ mcp: {
391
+ description: '3D plumbing pipe polyline in level-local meters tracking system, material, nominalSize, gravity slope, DFU/WSFU/gas loads, and framing penetrations.',
392
+ },
393
+ }
package/src/render.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Read-only viewer entry (`@kruschdev/pascal-plugin-plumbing/render`).
3
+ * Same plugin ID, contract version, schemas, defaults, 3D geometry, and 2D floorplan symbols
4
+ * as `plumbingPlugin`, with ZERO imports from `@pascal-app/editor` or `next`.
5
+ */
6
+
7
+ import type { AnyNodeDefinition, Plugin } from '@pascal-app/core'
8
+ import { plumbingEquipmentRenderDefinition } from './nodes/equipment'
9
+ import { plumbingFixtureRenderDefinition } from './nodes/fixture'
10
+ import { plumbingManifoldRenderDefinition } from './nodes/manifold'
11
+ import { plumbingPipeRunRenderDefinition } from './nodes/pipe-run'
12
+
13
+ export const PLUMBING_PLUGIN_ID = 'krusch:plumbing' as const
14
+ export const PLUMBING_SCHEDULE_VIEW_ID = 'krusch:plumbing:schedule' as const
15
+
16
+ export const plumbingRenderPlugin: Plugin = {
17
+ id: PLUMBING_PLUGIN_ID,
18
+ apiVersion: 1,
19
+ nodes: [
20
+ plumbingEquipmentRenderDefinition as unknown as AnyNodeDefinition,
21
+ plumbingManifoldRenderDefinition as unknown as AnyNodeDefinition,
22
+ plumbingFixtureRenderDefinition as unknown as AnyNodeDefinition,
23
+ plumbingPipeRunRenderDefinition as unknown as AnyNodeDefinition,
24
+ ],
25
+ }
26
+
27
+ export {
28
+ PlumbingEquipmentNode,
29
+ EquipmentKindEnum,
30
+ ElectricalDemandSchema,
31
+ plumbingEquipmentRenderDefinition,
32
+ buildPlumbingEquipmentGeometry,
33
+ buildPlumbingEquipmentFloorplan,
34
+ getPlumbingEquipmentPorts,
35
+ } from './nodes/equipment'
36
+
37
+ export {
38
+ PlumbingManifoldNode,
39
+ ManifoldKindEnum,
40
+ plumbingManifoldRenderDefinition,
41
+ buildPlumbingManifoldGeometry,
42
+ buildPlumbingManifoldFloorplan,
43
+ getPlumbingManifoldPorts,
44
+ } from './nodes/manifold'
45
+
46
+ export {
47
+ PlumbingFixtureNode,
48
+ FixtureKindEnum,
49
+ PipeNominalSizeEnum,
50
+ plumbingFixtureRenderDefinition,
51
+ buildPlumbingFixtureGeometry,
52
+ buildPlumbingFixtureFloorplan,
53
+ getPlumbingFixturePorts,
54
+ } from './nodes/fixture'
55
+
56
+ export {
57
+ PlumbingPipeRunNode,
58
+ PlumbingSystemEnum,
59
+ PipeMaterialEnum,
60
+ plumbingPipeRunRenderDefinition,
61
+ buildPlumbingPipeRunGeometry,
62
+ buildPlumbingPipeRunFloorplan,
63
+ getPlumbingPipeRunPorts,
64
+ } from './nodes/pipe-run'
@@ -0,0 +1,209 @@
1
+ 'use client'
2
+
3
+ /**
4
+ * Persisted ChatToolCard for `krusch:plumbing` (`PluginChatExtension`).
5
+ */
6
+
7
+ import type { ChatToolCardProps } from '@pascal-app/editor'
8
+ import { PLUMBING_SCHEDULE_VIEW_ID } from './plumbing-panel'
9
+
10
+ export default function PlumbingChatCard({ toolName, output, state, actions }: ChatToolCardProps) {
11
+ const data = output?.data as Record<string, unknown> | undefined
12
+ const rawFindings =
13
+ data?.findings ?? (data?.audit as { findings?: unknown } | undefined)?.findings
14
+ const findings = Array.isArray(rawFindings)
15
+ ? (rawFindings as Array<{ id: string; title: string; codeRef: string; nodeIds?: string[] }>)
16
+ : []
17
+ const scheduleObj = data?.schedule as
18
+ | {
19
+ fixtures?: unknown[]
20
+ loads?: { totalDfu?: number; peakDemandGpm?: number; recommendedBuildingDrain?: string }
21
+ }
22
+ | undefined
23
+ const loadsObj = (data?.loads ?? scheduleObj?.loads) as
24
+ | {
25
+ totalDfu?: number
26
+ totalWsfu?: number
27
+ peakDemandGpm?: number
28
+ recommendedBuildingDrain?: string
29
+ recommendedVentStack?: string
30
+ }
31
+ | undefined
32
+ const autoSummary = typeof data?.summary === 'string' ? data.summary : null
33
+ const bomObj = data?.bom as { grandTotalUsd?: number; totalLaborHours?: number } | undefined
34
+ const penetrations = Array.isArray(data?.penetrations) ? data.penetrations : null
35
+ const routedNodeId = typeof data?.nodeId === 'string' ? data.nodeId : null
36
+ const lengthFt = typeof data?.lengthFt === 'number' ? data.lengthFt : null
37
+ const slopeInPerFt = typeof data?.slopeInPerFt === 'number' ? data.slopeInPerFt : null
38
+ const showSlope =
39
+ slopeInPerFt !== null && (slopeInPerFt !== 0 || data?.system === 'dwv-drain')
40
+ const placedName = typeof data?.name === 'string' && data.name ? data.name : null
41
+ const placedEquipmentKind = typeof data?.equipmentKind === 'string' ? data.equipmentKind : null
42
+ const placedManifoldKind = typeof data?.manifoldKind === 'string' ? data.manifoldKind : null
43
+ const placedFixtureKind = typeof data?.fixtureKind === 'string' ? data.fixtureKind : null
44
+ const placedDemand = data?.electricalDemand as
45
+ | { required?: boolean; voltage?: number; breakerAmps?: number }
46
+ | null
47
+ | undefined
48
+ const placedPortCount = typeof data?.portCount === 'number' ? data.portCount : null
49
+ const placedDfu = typeof data?.dfu === 'number' ? data.dfu : null
50
+ const placedWsfu = typeof data?.wsfu === 'number' ? data.wsfu : null
51
+ const connectedPipeRunCount =
52
+ typeof data?.connectedPipeRunCount === 'number' ? data.connectedPipeRunCount : null
53
+
54
+ return (
55
+ <div
56
+ style={{
57
+ padding: 10,
58
+ borderRadius: 8,
59
+ border: '1px solid var(--border, rgba(255,255,255,0.16))',
60
+ fontSize: 12,
61
+ display: 'flex',
62
+ flexDirection: 'column',
63
+ gap: 6,
64
+ }}
65
+ >
66
+ <div style={{ display: 'flex', justifyContent: 'space-between', fontWeight: 600 }}>
67
+ <span>{toolName}</span>
68
+ <span style={{ fontSize: 11, opacity: 0.75 }}>{state}</span>
69
+ </div>
70
+ {output?.text && <div style={{ opacity: 0.85 }}>{output.text}</div>}
71
+
72
+ {/* Summary for plumbing_autopopulate */}
73
+ {autoSummary && (
74
+ <div style={{ fontSize: 11, opacity: 0.9 }}>
75
+ <strong>Auto-Populate:</strong> {autoSummary}
76
+ </div>
77
+ )}
78
+
79
+ {/* Summary for plumbing_calculate_loads */}
80
+ {!scheduleObj && loadsObj && (
81
+ <div style={{ fontSize: 11 }}>
82
+ <strong>Loads:</strong> {loadsObj.totalDfu ?? 0} DFU · {loadsObj.totalWsfu ?? 0} WSFU ({loadsObj.peakDemandGpm ?? 0} GPM) · Drain{' '}
83
+ {loadsObj.recommendedBuildingDrain ?? '-'} · Stack {loadsObj.recommendedVentStack ?? '-'}
84
+ </div>
85
+ )}
86
+
87
+ {/* Summary for plumbing_generate_schedule */}
88
+ {(scheduleObj || bomObj) && (
89
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 3, fontSize: 11 }}>
90
+ {scheduleObj?.loads && (
91
+ <div>
92
+ <strong>Schedule:</strong> {scheduleObj.fixtures?.length ?? 0} fixtures · {scheduleObj.loads.totalDfu ?? 0} DFU ·{' '}
93
+ {scheduleObj.loads.peakDemandGpm ?? 0} GPM · Drain {scheduleObj.loads.recommendedBuildingDrain ?? '-'}
94
+ </div>
95
+ )}
96
+ {bomObj && typeof bomObj.grandTotalUsd === 'number' && (
97
+ <div>
98
+ <strong>Estimated BOM:</strong> ${bomObj.grandTotalUsd.toLocaleString(undefined, { minimumFractionDigits: 2 })} (
99
+ {bomObj.totalLaborHours ?? 0} labor hrs)
100
+ </div>
101
+ )}
102
+ {penetrations && (
103
+ <div>
104
+ <strong>Framing Drill List:</strong> {penetrations.length} stud/plate penetration(s)
105
+ </div>
106
+ )}
107
+ </div>
108
+ )}
109
+
110
+ {/* Summary for plumbing_place_equipment / plumbing_place_manifold / plumbing_place_fixture */}
111
+ {lengthFt === null &&
112
+ routedNodeId &&
113
+ (placedEquipmentKind || placedManifoldKind || placedFixtureKind) && (
114
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 11 }}>
115
+ <span>
116
+ {placedEquipmentKind && (
117
+ <>
118
+ <strong>Placed Equipment:</strong> {placedName ?? placedEquipmentKind}
119
+ {placedDemand?.required ? ` · ${placedDemand.voltage}V ${placedDemand.breakerAmps}A` : ''}
120
+ </>
121
+ )}
122
+ {placedManifoldKind && (
123
+ <>
124
+ <strong>Placed Manifold:</strong> {placedName ?? placedManifoldKind}
125
+ {placedPortCount !== null ? ` (${placedPortCount} ports)` : ''}
126
+ </>
127
+ )}
128
+ {placedFixtureKind && (
129
+ <>
130
+ <strong>Placed Fixture:</strong> {placedName ?? placedFixtureKind}
131
+ {placedDfu !== null ? ` · ${placedDfu} DFU` : ''}
132
+ {placedWsfu !== null ? ` · ${placedWsfu} WSFU` : ''}
133
+ {connectedPipeRunCount && connectedPipeRunCount > 0
134
+ ? ` · ${connectedPipeRunCount} pipe(s) routed`
135
+ : ''}
136
+ </>
137
+ )}
138
+ </span>
139
+ <button
140
+ type="button"
141
+ onClick={() => actions.select([routedNodeId])}
142
+ style={{ background: 'transparent', border: 'none', color: '#38bdf8', cursor: 'pointer', fontSize: 11 }}
143
+ >
144
+ Select
145
+ </button>
146
+ </div>
147
+ )}
148
+
149
+ {/* Summary for plumbing_route_pipe */}
150
+ {lengthFt !== null && (
151
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 11 }}>
152
+ <span>
153
+ <strong>Routed Pipe:</strong> {lengthFt} ft
154
+ {showSlope && (
155
+ <span style={slopeInPerFt! <= 0 ? { color: '#ef4444', fontWeight: 600 } : undefined}>
156
+ {` · ${slopeInPerFt}"/ft slope`}
157
+ </span>
158
+ )}
159
+ {penetrations ? ` · ${penetrations.length} bore(s)` : ''}
160
+ </span>
161
+ {routedNodeId && (
162
+ <button
163
+ type="button"
164
+ onClick={() => actions.select([routedNodeId])}
165
+ style={{ background: 'transparent', border: 'none', color: '#38bdf8', cursor: 'pointer', fontSize: 11 }}
166
+ >
167
+ Select
168
+ </button>
169
+ )}
170
+ </div>
171
+ )}
172
+
173
+ {/* Summary for plumbing_audit_ipc */}
174
+ {findings.slice(0, 4).map((f) => (
175
+ <div key={f.id} style={{ display: 'flex', justifyContent: 'space-between', fontSize: 11 }}>
176
+ <span>
177
+ <strong>{f.codeRef}</strong>: {f.title}
178
+ </span>
179
+ {f.nodeIds && f.nodeIds.length > 0 && (
180
+ <button
181
+ type="button"
182
+ onClick={() => actions.select(f.nodeIds!)}
183
+ style={{ background: 'transparent', border: 'none', color: '#38bdf8', cursor: 'pointer', fontSize: 11 }}
184
+ >
185
+ Select
186
+ </button>
187
+ )}
188
+ </div>
189
+ ))}
190
+ <div style={{ display: 'flex', gap: 8, marginTop: 4 }}>
191
+ <button
192
+ type="button"
193
+ onClick={() => actions.openView(PLUMBING_SCHEDULE_VIEW_ID, { beside: true })}
194
+ style={{
195
+ padding: '4px 8px',
196
+ borderRadius: 5,
197
+ border: '1px solid rgba(37,99,235,0.55)',
198
+ background: 'rgba(37,99,235,0.18)',
199
+ color: 'inherit',
200
+ cursor: 'pointer',
201
+ fontSize: 11,
202
+ }}
203
+ >
204
+ Open Plumbing Schedule
205
+ </button>
206
+ </div>
207
+ </div>
208
+ )
209
+ }