import { notFound } from 'next/navigation';
import Link from 'next/link';
import { Register } from '@/utils/register_parser';
import RegisterDetail from '@/app/registers/RegisterDetail';
import {Container, Row} from "react-bootstrap";
import { getRegisters } from '@/services/register.service';

export default async function RegisterDetailPage({ params }: { params: { hex: string } }) {
    const registers = await getRegisters();
    const targetHex = decodeURIComponent((await params).hex).toLowerCase();

    const register = registers.find(r => r.hex_address.toLowerCase() === targetHex);

    if (!register) return notFound();


    return (
        <Container fluid className="py-4">
            <div className="mb-3">
                <Link href="/registers" className="btn btn-secondary">← Back to Registers</Link>
            </div>
            <Row>
                <RegisterDetail register={register} />
            </Row>
        </Container>
    );
}
