import { create } from 'zustand'; import type { ConnectionState } from '../types/connection'; import { calculateLoadCombinations } from '../calculations/loadCombinations'; import { calculateLimitStates } from '../calculations/strength'; import { performGeometryChecks } from '../calculations/geometry'; import { performDesignChecks } from '../calculations/designChecks'; export const useConnectionStore = create((set, get) => ({ connectionType: 'double-angle', support: { type: 'column-flange', designation: 'W14X53', similarConnectionOtherSide: false, }, beam: { designation: 'W12X26', gapFromSupport: 0.75, topFlangeCopeLengthC: false, topFlangeCopeHeightDc: false, bottomFlangeCopeLengthC: false, bottomFlangeCopeHeightDc: false, }, angle: { legOnSupport: 4.0, legOnBeam: 3.5, thickness: 0.375, connectionMethod: 'bolted', edgeDistanceHorizontal: 1.25, edgeDistanceVertical: 1.25, eccentricityToBeamCL: 1.0, }, bolts: { numberOfRows: 3, diameter: 0.75, grade: 'A325', spacing: 3.0, threadsIncluded: true, }, weld: { type: 'fillet', size: 0.25, strength: 70.0, }, materials: { support: { fy: 50.0, fu: 65.0, }, beam: { fy: 50.0, fu: 65.0, }, angle: { fy: 36.0, fu: 58.0, }, modulusOfElasticity: 29000, }, loads: { dead: 10.0, live: 5.0, rLive: 0.0, snow: 0.0, wind: 0.0, seismic: 0.0, }, designMethod: 'LRFD', loadCombinationOption: 'nominal-loads', loadCombinations: [], limitStates: [], geometryChecks: [], designCheck: { connectionStrengthRatio: 0, designCheckRatio: 0, geometricConstraintsCheck: 'OK', }, setConnectionType: (type) => { set({ connectionType: type }); get().calculate(); }, setSupport: (support) => { set((state) => ({ support: { ...state.support, ...support }, })); get().calculate(); }, setBeam: (beam) => { set((state) => ({ beam: { ...state.beam, ...beam }, })); get().calculate(); }, setAngle: (angle) => { set((state) => ({ angle: { ...state.angle, ...angle }, })); get().calculate(); }, setBolts: (bolts) => { set((state) => ({ bolts: { ...state.bolts, ...bolts }, })); get().calculate(); }, setWeld: (weld) => { set((state) => ({ weld: { ...state.weld, ...weld }, })); get().calculate(); }, setMaterials: (materials) => { set((state) => ({ materials: { support: { ...state.materials.support, ...(materials.support || {}) }, beam: { ...state.materials.beam, ...(materials.beam || {}) }, angle: { ...state.materials.angle, ...(materials.angle || {}) }, modulusOfElasticity: materials.modulusOfElasticity ?? state.materials.modulusOfElasticity, }, })); get().calculate(); }, setLoads: (loads) => { set((state) => ({ loads: { ...state.loads, ...loads }, })); get().calculate(); }, setDesignMethod: (method) => { set({ designMethod: method }); get().calculate(); }, setLoadCombinationOption: (option) => { set({ loadCombinationOption: option }); get().calculate(); }, calculate: () => { const state = get(); // Calculate load combinations const loadCombinations = calculateLoadCombinations( state.loads, state.designMethod, state.loadCombinationOption ); // Calculate limit states const limitStates = calculateLimitStates( state.connectionType, state.support, state.beam, state.angle, state.bolts, state.weld, state.materials, state.designMethod ); // Perform geometry checks const geometryChecks = performGeometryChecks( state.connectionType, state.support, state.beam, state.angle, state.bolts ); // Perform design checks const designCheck = performDesignChecks( loadCombinations, limitStates, geometryChecks ); set({ loadCombinations, limitStates, geometryChecks, designCheck, }); }, }));