import { useState } from 'react' import { Box, Flex, Heading, Text, Button, Input, Select, Textarea, SimpleGrid, Card, Tabs, Table, VStack, createListCollection, } from '@chakra-ui/react' import { FiAlertTriangle } from 'react-icons/fi' import client from '../../api/client' import { useApp } from '../../stores/AppContext' const SCOPE_OPTIONS = ['all', 'server', 'partition'] const SERVER_OPTIONS = ['na', 'eu', 'sea', 'sa', 'oc'] const PARTITION_OPTIONS = ['parrish', 'sietch', 'bazar'] const serverCollection = createListCollection({ items: SERVER_OPTIONS.map((s) => ({ value: s, label: s.toUpperCase() })), }) const partitionCollection = createListCollection({ items: PARTITION_OPTIONS.map((p) => ({ value: p, label: p })), }) const itemFieldCollection = createListCollection({ items: [ { value: 'stack_size', label: 'stack_size' }, { value: 'quality_level', label: 'quality_level' }, { value: 'durability', label: 'durability' }, { value: 'ammo', label: 'ammo' }, ], }) const demoStateCollection = createListCollection({ items: [ { value: 'true', label: 'Demo' }, { value: 'false', label: 'Normal' }, ], }) const limitCollection = createListCollection({ items: [10, 25, 50, 100, 250].map((n) => ({ value: String(n), label: `${n} entries` })), }) export default function AdminTools() { const [tab, setTab] = useState<'broadcast' | 'economy' | 'world' | 'character' | 'functions' | 'raw' | 'audit'>('broadcast') const { dispatch } = useApp() return ( Admin Tools setTab(e.value as any)} mb={6}> {([ { key: 'broadcast', label: 'Broadcast' }, { key: 'economy', label: 'Economy' }, { key: 'world', label: 'World' }, { key: 'character', label: 'Character' }, { key: 'functions', label: 'Functions' }, { key: 'raw', label: 'Raw Query' }, { key: 'audit', label: 'Audit Log' }, ] as const).map((t) => ( {t.label} ))} ) } function BroadcastTab({ dispatch }: { dispatch: any }) { const [message, setMessage] = useState('') const [scope, setScope] = useState('all') const [server, setServer] = useState('na') const [partition, setPartition] = useState('parrish') const [sending, setSending] = useState(false) const handleSend = async () => { if (!message.trim()) return setSending(true) try { const payload: any = { message: message.trim() } if (scope === 'server') payload.server = server if (scope === 'partition') { payload.server = server payload.partition = partition } const res = await client.post('/broadcast', payload) if (res.data.success) { dispatch({ type: 'ADD_TOAST', payload: { message: 'Broadcast sent', type: 'success' } }) setMessage('') } else { dispatch({ type: 'ADD_TOAST', payload: { message: res.data.error || 'Failed', type: 'error' } }) } } catch (e: any) { dispatch({ type: 'ADD_TOAST', payload: { message: e.response?.data?.error || 'Failed', type: 'error' } }) } finally { setSending(false) } } return ( Scope {SCOPE_OPTIONS.map((s) => ( ))} {scope !== 'all' && ( Server setServer(e.value[0])}> {serverCollection.items.map((item) => ( {item.label} ))} )} {scope === 'partition' && ( Partition setPartition(e.value[0])}> {partitionCollection.items.map((item) => ( {item.label} ))} )} Message