import { useReducer } from 'react'; import StepOperator from './StepOperator'; import StepGroundLoops from './StepGroundLoops'; import StepAccessControl from './StepAccessControl'; import StepCustomerInfo from './StepCustomerInfo'; import QuoteSummary from './QuoteSummary'; const initialState = { step: 1, operator: null, armChoice: null, optionalParts: [], groundLoops: { needed: false, style: null, types: [], typeSizes: {}, }, accessControl: [], remoteButtons: 4, remoteQuantity: 1, customerInfo: { name: '', project: '' }, }; function reducer(state, action) { switch (action.type) { case 'SELECT_OPERATOR': return { ...state, operator: action.payload, armChoice: null, optionalParts: [], step: 2 }; case 'SET_ARM_CHOICE': return { ...state, armChoice: action.payload }; case 'TOGGLE_OPTIONAL_PART': { const id = action.payload; const exists = state.optionalParts.includes(id); return { ...state, optionalParts: exists ? state.optionalParts.filter((p) => p !== id) : [...state.optionalParts, id], }; } case 'SET_GROUND_LOOPS_NEEDED': return { ...state, groundLoops: { needed: action.payload, style: null, types: [], typeSizes: {} }, step: action.payload ? state.step : state.step + 1, }; case 'SET_GROUND_LOOP_STYLE': return { ...state, groundLoops: { ...state.groundLoops, style: action.payload }, }; case 'TOGGLE_GROUND_LOOP_TYPE': { const id = action.payload; const exists = state.groundLoops.types.includes(id); const newTypeSizes = { ...state.groundLoops.typeSizes }; if (!exists) { newTypeSizes[id] = '4x8'; } else { delete newTypeSizes[id]; } return { ...state, groundLoops: { ...state.groundLoops, types: exists ? state.groundLoops.types.filter((t) => t !== id) : [...state.groundLoops.types, id], typeSizes: newTypeSizes, }, }; } case 'TOGGLE_ACCESS_CONTROL': { const id = action.payload; const exists = state.accessControl.includes(id); return { ...state, accessControl: exists ? state.accessControl.filter((a) => a !== id) : [...state.accessControl, id], remoteButtons: id === 'remote-kit' && !exists ? 4 : state.remoteButtons, }; } case 'SET_REMOTE_BUTTONS': return { ...state, remoteButtons: action.payload }; case 'SET_REMOTE_QUANTITY': return { ...state, remoteQuantity: Math.max(1, action.payload) }; case 'SET_CUSTOMER_INFO': return { ...state, customerInfo: action.payload }; case 'NEXT_STEP': return { ...state, step: Math.min(state.step + 1, 5) }; case 'PREV_STEP': return { ...state, step: Math.max(state.step - 1, 1) }; case 'SET_GROUND_LOOP_SIZE': return { ...state, groundLoops: { ...state.groundLoops, typeSizes: { ...state.groundLoops.typeSizes, [action.payload.typeId]: action.payload.sizeId, }, }, }; case 'GO_TO_STEP': return { ...state, step: Math.min(action.payload, 5) }; case 'RESET': return { ...initialState }; default: return state; } } export default function Wizard({ pricing, onLogout }) { const [state, dispatch] = useReducer(reducer, initialState); const { step, operator, armChoice, optionalParts, groundLoops, accessControl, remoteButtons, remoteQuantity, customerInfo } = state; const steps = [ { num: 1, label: 'Operator' }, { num: 2, label: 'Ground Loops' }, { num: 3, label: 'Access Control' }, { num: 4, label: 'Customer' }, { num: 5, label: 'Quote' }, ]; return (
Select your configuration to generate a detailed cost estimate