import React from "react";
import AppLayout from "@/layouts/app-layout";
import { Button, Card, Container, Group, Title } from "@mantine/core";
import { IconArrowLeft } from "@tabler/icons-react";
import { Link } from "@inertiajs/react";
import UserForm from "@/forms/management/UserForm";
import { Role, User } from "@/types";

interface Props {
    roles: Role[];
    managers: { value: string; label: string }[];
    user: User;
}

export default function Page({ roles, managers, user }: Props) {
    return (
        <AppLayout>
            <Container size="lg" px="xs">
                <Group position="apart" mb="md">
                    <Title order={2}>Edit User</Title>
                    <Button
                        component={Link}
                        href={route("management.users.index")}
                        leftIcon={<IconArrowLeft size={16} />}
                        variant="outline"
                    >
                        Back to users
                    </Button>
                </Group>

                <Card>
                    <UserForm roles={roles} managers={managers} user={user} status="update" />
                </Card>
            </Container>
        </AppLayout>
    );
}
