import { Head, router } from '@inertiajs/react';
import Heading from '@/components/heading';
import { dashboard } from '@/routes';
import { index, show } from '@/routes/admin/fixed-assets';
import { FixedAssetForm } from './fixed-asset-form';
import type { FixedAssetFormData, MethodOption } from './fixed-asset-form';

type Accounts = {
    asset_accounts: Array<{ id: number; code: string; label: string }>;
    depreciation_accounts: Array<{ id: number; code: string; label: string }>;
    expense_accounts: Array<{ id: number; code: string; label: string }>;
};

export default function FixedAssetsEdit({
    asset,
    accounts,
    depreciationMethods,
}: {
    asset: FixedAssetFormData;
    accounts: Accounts;
    depreciationMethods: MethodOption[];
}) {
    return (
        <>
            <Head title={`Modifier ${asset.code}`} />
            <div className="flex h-full flex-1 flex-col gap-6 p-4 md:p-6">
                <Heading title="Modifier l'immobilisation" description={asset.label} />
                <FixedAssetForm
                    accounts={accounts}
                    depreciationMethods={depreciationMethods}
                    asset={asset}
                    onCancel={() => router.get(show.url(asset.id))}
                />
            </div>
        </>
    );
}

FixedAssetsEdit.layout = {
    breadcrumbs: [
        { title: 'Tableau de bord', href: dashboard() },
        { title: 'Immobilisations', href: index() },
        { title: 'Modifier', href: '#' },
    ],
};
