import { content } from "@deadhead/content"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { useNavigate } from "react-router"; import { useApi } from "../api/context"; import { formatCredits } from "../format"; import { errorMessage, useLoadedPlayer } from "../state/actions"; import { PLAYER_STATE_KEY } from "../state/player"; import { Art, Button, Sheet } from "../ui"; /** * The one-time deal (decision 0.5.30): shown when the server says it is * available, after any delivery summary has been dismissed. There is no * decline option. */ export function DealModal() { const state = useLoadedPlayer(); const api = useApi(); const queryClient = useQueryClient(); const navigate = useNavigate(); const accept = useMutation({ mutationFn: () => api.call("acceptDeal", {}), onSuccess: (newState) => { queryClient.setQueryData(PLAYER_STATE_KEY, newState); void navigate("/"); }, }); if (!state.tutorial?.dealAvailable || state.summaries.length > 0) return null; const { dealLoanAmount, loanRepaymentShare } = content.config; const courier = content.shipModel("courier")!; const veteran = content.veteranPilot; return (

Old Halvorsen is retiring. He'll sell you his Courier and his Earth bay, and his pilot comes with them. Pay him back out of every job.

You get
A {courier.name} and a bay at Earth
Pilot
…and {veteran.name}. {veteran.bio}
Loan
{formatCredits(dealLoanAmount)}
Repayment
{Math.round(loanRepaymentShare * 100)}% of every payout until it's paid off
{accept.isError && (

{errorMessage(accept.error)}

)}
); }