import LinkRouting, {NextLinkComposed} from "@/core/components/LinkRouting";
import CenterLayout from "@/layouts/CenterLayout";
import FullPageLayout from "@/layouts/FullPageLayout";
import useUser from "@/lib/app/hooks/useUser";
import {Box, Button, Grid, Stack} from "@mui/material";
import {useTranslations} from "next-intl";
import {useSearchParams} from "next/navigation";
import SvgDashboard from "@/core/components/svgs/SvgDashboard";

const RegisterComponent = () => {
    const t = useTranslations();
    const {isAuth} = useUser();

    const searchParams = useSearchParams();
    const backUrlDecodedPath = searchParams.get("back_url");

    return (
        <FullPageLayout sx={{p: 1}}>
            <CenterLayout spacing={3}>
                <SvgDashboard width={300} height={200}/>
                {isAuth ? (
                    <Button
                        variant="contained"
                        component={NextLinkComposed}
                        to={{
                            pathname: "/dashboard",
                        }}
                    >
                        {t("dashboard")}
                    </Button>
                ) : (
                    <Box>
                        <Grid
                            container
                            rowSpacing={{xs: 1, sm: 0}}
                            sx={{
                                flexDirection: {xs: "column", sm: "row"},
                                alignItems: "center",
                            }}
                        >
                            <Grid item xs={12} sm={6} sx={{px: {xs: 0, sm: 1}}}>
                                <Button
                                    sx={{whiteSpace: "nowrap"}}
                                    variant="contained"
                                    size="large"
                                    component={NextLinkComposed}
                                    to={{
                                        pathname: "register/navy",
                                    }}
                                >
                                    {t("register_navy")}
                                </Button>
                            </Grid>
                            {/*<Grid item xs={12} sm={6} sx={{px: {xs: 0, sm: 1}}}>*/}
                            {/*    <Button*/}
                            {/*        sx={{whiteSpace: "nowrap"}}*/}
                            {/*        variant="contained"*/}
                            {/*        size="large"*/}
                            {/*        component={NextLinkComposed}*/}
                            {/*        to={{*/}
                            {/*            pathname: "register/welfare-services",*/}
                            {/*        }}*/}
                            {/*    >*/}
                            {/*        {t("register_welfare_services")}*/}
                            {/*    </Button>*/}
                            {/*</Grid>*/}
                        </Grid>
                    </Box>
                )}
            </CenterLayout>
            <Stack direction="row" alignItems="center" justifyContent="center">
                <LinkRouting
                    sx={{margin: 2}}
                    href={
                        backUrlDecodedPath
                            ? decodeURIComponent(backUrlDecodedPath)
                            : "/"
                    }
                >
                    {t("RegisterPage.link_routing_back_to")}{" "}
                    {backUrlDecodedPath
                        ? t("RegisterPage.link_routing_previuos_page")
                        : t("LoginPage.link_routing_main_page")}
                </LinkRouting>
            </Stack>
        </FullPageLayout>
    );
};

export default RegisterComponent;
