import type { Route } from './+types/route' import { formatCEP } from '@brazilian-utils/brazilian-utils' import { AlertCircleIcon, ArrowLeftRightIcon, HelpCircleIcon } from 'lucide-react' import { useEffect } from 'react' import { Link } from 'react-router' import { Currency } from '@repo/ui/components/currency' import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from '@repo/ui/components/ui/breadcrumb' import { Card, CardContent, CardHeader, CardTitle } from '@repo/ui/components/ui/card' import { Item, ItemContent, ItemGroup, ItemTitle } from '@repo/ui/components/ui/item' import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow } from '@repo/ui/components/ui/table' import { request as req } from '@repo/util/request' import { Abbr } from '@repo/ui/components/abbr' import { Badge } from '@repo/ui/components/ui/badge' import { Button } from '@repo/ui/components/ui/button' import { Kbd } from '@repo/ui/components/ui/kbd' import { cn } from '@repo/ui/lib/utils' import { labels, statuses, type Order as Order_ } from '@repo/ui/routes/orders/data' import type { CreditCard as CreditCard_ } from '../_.$orgid.enrollments.buy/payment' import type { Address } from '../_.$orgid.enrollments.buy/review' import { useWizardStore } from '../_.$orgid.enrollments.buy/store' export function meta() { return [ { title: 'Detalhes do pagamento' } ] } const PaymentMethodComponent = { PIX: Pix, BANK_SLIP: BankSlip, CREDIT_CARD: CreditCard } type Item_ = { id: string name: string unit_price: number quantity: number } type User = { id: string name: string } type Order = Order_ & { items: Item_[] interest_amount: number due_date: string created_at: string subtotal: number discount: number address: Address credit_card?: CreditCard_ coupon?: string installments?: number created_by?: User } export async function loader({ context, request, params }: Route.LoaderArgs) { const order = (await req({ url: `/orders/${params.id}`, context, request }).then((r) => r.json())) as Order return { order } } export default function Route({ loaderData: { order } }: Route.ComponentProps) { const { reset } = useWizardStore() const { coupon, address, total, payment_method, interest_amount, discount, subtotal, items = [] } = order const Component = PaymentMethodComponent[payment_method] useEffect(() => { reset() }, []) return (
Pagamentos Detalhes do pagamento Detalhes do pagamento Endereço de cobrança
    {address?.address1} {address?.address2 ? <>, {address?.address2} : null}
    {address?.neighborhood}
    {address?.city}, {address?.state}
    {formatCEP(address?.postcode)}
Forma de pagamento
{Component && }
Curso Quantidade Valor unit. Total {items?.map(({ name, unit_price, quantity }, index) => { return ( {name} {quantity} {unit_price} {unit_price * quantity} ) })} {/* Summary */} Subtotal {subtotal} {/* Discount */} Descontos {coupon && ( {coupon} )} {discount} {/* Interest */} {interest_amount ? ( Juros {interest_amount} ) : ( <> )} {/* Total */} Total {total}
{/*
{JSON.stringify(order, null, 2)}
*/}
) } function Status({ status: s }: { status: string }) { const status = labels[s] ?? s const { icon: Icon, color } = statuses?.[s] ?? { icon: HelpCircleIcon } return ( {status} ) } type PaymentMethodProps = { status: string total: number installments: number } type CreditCardProps = PaymentMethodProps & { stats: { last_attempt_succeeded: boolean } credit_card: { last4: string; brand: string } } function CreditCard({ status, total, credit_card, installments, stats }: CreditCardProps) { return ( <>

{installments}x {total / Number(installments)}

{!stats.last_attempt_succeeded ? (
) : null} ) } type BankSlipProps = PaymentMethodProps & {} function BankSlip({ status }: BankSlipProps) { return ( ) } type PixProps = PaymentMethodProps & {} function Pix({}: PixProps) { return <>Pix }