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 (

Gate Operator Quotation System

Select your configuration to generate a detailed cost estimate

{step === 1 && ( dispatch({ type: 'SELECT_OPERATOR', payload: id })} onSetArmChoice={(id) => dispatch({ type: 'SET_ARM_CHOICE', payload: id })} onToggleOptionalPart={(id) => dispatch({ type: 'TOGGLE_OPTIONAL_PART', payload: id })} onNext={() => dispatch({ type: 'NEXT_STEP' })} /> )} {step === 2 && ( dispatch({ type: 'SET_GROUND_LOOPS_NEEDED', payload: needed })} onSetStyle={(id) => dispatch({ type: 'SET_GROUND_LOOP_STYLE', payload: id })} onToggleType={(id) => dispatch({ type: 'TOGGLE_GROUND_LOOP_TYPE', payload: id })} onSetSize={(typeId, sizeId) => dispatch({ type: 'SET_GROUND_LOOP_SIZE', payload: { typeId, sizeId } })} onNext={() => dispatch({ type: 'NEXT_STEP' })} onBack={() => dispatch({ type: 'PREV_STEP' })} /> )} {step === 3 && ( dispatch({ type: 'TOGGLE_ACCESS_CONTROL', payload: id })} onSetRemoteButtons={(count) => dispatch({ type: 'SET_REMOTE_BUTTONS', payload: count })} onSetRemoteQuantity={(qty) => dispatch({ type: 'SET_REMOTE_QUANTITY', payload: qty })} onBack={() => dispatch({ type: 'PREV_STEP' })} onNext={() => dispatch({ type: 'NEXT_STEP' })} /> )} {step === 4 && ( dispatch({ type: 'SET_CUSTOMER_INFO', payload: info })} onBack={() => dispatch({ type: 'PREV_STEP' })} onNext={() => dispatch({ type: 'NEXT_STEP' })} /> )} {step === 5 && ( dispatch({ type: 'PREV_STEP' })} onNew={() => dispatch({ type: 'RESET' })} /> )}
); }