import { IServer } from '../interfaces/servers'
import { useServerIps } from '../hooks/swrHooks'
import { Flex, Table } from '@mantine/core'

function ServerData({ id }: IServer) {
    const { serverIps } = useServerIps(id, 0, 10)

    const serverIpsColumns = [
        { field: 'id', headerName: 'ID', type: 'number' },
        { field: 'server_id', headerName: 'Server ID', type: 'number' },
        { field: 'name', headerName: 'Название', type: 'string' },
        { field: 'is_actual', headerName: 'Действителен', type: 'boolean' },
        { field: 'ip', headerName: 'IP', type: 'string' },
        { field: 'servername', headerName: 'Название сервера', type: 'string' },
    ]

    return (
        <Flex direction='column' p='sm'>
            {serverIps &&
                <Table highlightOnHover>
                    <Table.Thead>
                        <Table.Tr>
                            {serverIpsColumns.map(column => (
                                <Table.Th key={column.field}>{column.headerName}</Table.Th>
                            ))}
                        </Table.Tr>
                    </Table.Thead>
                    <Table.Tbody>
                        <Table.Tr>
                            {serverIpsColumns.map(column => (
                                <Table.Td key={column.field}>{serverIps ? serverIps[column.field] : ''}</Table.Td>
                            ))}
                        </Table.Tr>
                    </Table.Tbody>
                </Table>
            }
        </Flex>
    )
}

export default ServerData