export function usePriceCalculator() {/**
- Calculate the total price based on base rate, distance and duration
- @param baseRate The hourly rate for the selected vehicle
- @param distance The distance in miles
- @param duration The duration in minutes
- @returns The calculated price components
*/
const calculatePrice = (baseRate: number, distance: number, duration: number) => {
// Rate per mile (typically 25-50% of the hourly rate / 30 miles)
const mileRate = baseRate * 0.3 / 30; // Rate per minute (hourly rate / 60 minutes)
const minuteRate = baseRate / 60; // Calculate fares
const baseFare = baseRate; // Minimum 1 hour charge
const distanceFare = distance * mileRate;
const timeFare = duration * minuteRate; // Calculate total with minimum 1 hour charge
const total = Math.max(baseRate, baseFare + distanceFare + timeFare); return {
baseFare,
distanceFare,
timeFare,
total
};
}; return {
calculatePrice
};
}
Laisser un commentaire