import React, { useState, useMemo } from 'react'; import { Wallet, Users, Info } from 'lucide-react'; import { useTourStore } from './useTourStore.js'; export const ExpenseManager = () => { const { legs } = useTourStore(); const [adults, setAdults] = useState(2); const [children, setChildren] = useState(1); const [discount, setDiscount] = useState(30); const totals = useMemo(() => { const totalAmount = legs.reduce((acc, leg) => acc + leg.expenses.reduce((lAcc: number, exp: any) => lAcc + Number(exp.amount), 0), 0 ); const childRateFactor = 1 - (discount / 100); const weightedCount = adults + (children * childRateFactor); const adultPrice = totalAmount / weightedCount; const childPrice = adultPrice * childRateFactor; return { total: totalAmount, adultPrice: Math.round(adultPrice), childPrice: Math.round(childPrice) }; }, [legs, adults, children, discount]); return (
Tổng chi phí chuyến đi
Mỗi người lớn
{totals.adultPrice.toLocaleString()}đ
Mỗi trẻ em (-{discount}%)
{totals.childPrice.toLocaleString()}đ
Chi phí được tự động tính toán dựa trên hóa đơn của các chặng.