import { createFileRoute } from '@tanstack/react-router' import { useState, useEffect } from 'react' import { Stack, SimpleGrid, Card, Text, Group, Badge, Loader, Center, Drawer, TextInput, NumberInput, Textarea, Button, ActionIcon, Tooltip, Tabs, Switch, } from '@pikku/mantine/core' import { Pencil, Plus, Sailboat, Route as RouteIcon } from 'lucide-react' import { useQueryClient } from '@tanstack/react-query' import { notifications } from '@mantine/notifications' import { usePikkuQuery, usePikkuMutation } from '@perauset/functions-sdk/pikku/api.gen' import { usePermission } from '@/lib/permissions' import { PageHeader } from '@perauset/components' import { m } from '@/i18n/messages' import { useLocale } from '@/i18n/config' import { asI18n } from '@pikku/react' export const Route = createFileRoute('/_authenticated/boats/manage')({ component: BoatManagePage, }) type Boat = { boatId: string name: string passengerCapacity: number cargoCapacityKg: number | null isActive: boolean notes: string | null } type BoatRoute = { routeId: string name: string origin: string destination: string isActive: boolean } const cardStyle = { backgroundColor: '#ffffff', boxShadow: '0 2px 12px rgba(61, 43, 31, 0.08), 0 1px 4px rgba(61, 43, 31, 0.04)', } function CreateBoatDrawer({ opened, onClose }: { opened: boolean; onClose: () => void }) { const queryClient = useQueryClient() const [name, setName] = useState('') const [passengerCapacity, setPassengerCapacity] = useState(1) const [cargoCapacityKg, setCargoCapacityKg] = useState(undefined) const [notes, setNotes] = useState('') const resetForm = () => { setName('') setPassengerCapacity(1) setCargoCapacityKg(undefined) setNotes('') } const mutation = usePikkuMutation('createBoat', { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['listBoats'] }) notifications.show({ title: 'Boat created', message: 'New boat has been added to the fleet.', color: 'green' }) resetForm() onClose() }, onError: (err) => notifications.show({ title: 'Error', message: err.message || 'Failed to create boat.', color: 'red' }), }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (!name) { notifications.show({ title: 'Missing fields', message: 'Name is required.', color: 'red' }) return } mutation.mutate({ name, passengerCapacity, cargoCapacityKg: cargoCapacityKg || undefined, notes: notes || undefined, }) } return (
setName(e.currentTarget.value)} required /> setPassengerCapacity(Number(val) || 1)} min={1} /> setCargoCapacityKg(val ? Number(val) : undefined)} min={0} suffix={asI18n(' kg')} />