import React, { useState, useMemo } from 'react'; import { Wallet, Users, Info } from 'lucide-react'; import { useTourStore } from './useTourStore'; 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 (

Cấu hình thành viên

setAdults(Number(e.target.value))} className="w-full p-2 bg-gray-50 rounded-lg border-none focus:ring-2 focus:ring-blue-500" />
setChildren(Number(e.target.value))} className="w-full p-2 bg-gray-50 rounded-lg border-none focus:ring-2 focus:ring-blue-500" />
setDiscount(Number(e.target.value))} className="w-full p-2 bg-gray-50 rounded-lg border-none focus:ring-2 focus:ring-blue-500" />

Tổng chi phí chuyến đi

{totals.total.toLocaleString()} VND

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.

); };