import React, { useCallback } from "react";
import { Page } from "@/pages/base";
import { Management } from "@/management/main";
import { Container, Dialog, Typography } from "@material-ui/core";
import { Async } from "@/components/async";
import { useTranslation } from "react-i18next";
import { useRouteMatch } from "react-router-dom";
import { useAsync } from "@/hooks";
import { Edition } from "@/data/edition";
import api from "@/management/api";
import { Form, Formik } from "formik";
import { useSpacing } from "@/styles";
import { EditionForm } from "@/management/edition/form";

const title = "edition.settings.title";

export function EditionSettings() {
    const { t } = useTranslation("management");
    const { params } = useRouteMatch();
    const spacing = useSpacing();

    const edition = useAsync<Edition>(useCallback(() => api.edition.details(params.edition), [params.edition]))

    const handleSubmit = () => {};

    return <Page>
        <Page.Header maxWidth="md">
            <Management.Breadcrumbs>
                <Typography color="textPrimary">{ t(title) }</Typography>
            </Management.Breadcrumbs>
            <Page.Title>{ t(title) }</Page.Title>
        </Page.Header>
        <Container maxWidth="md">
            <Async async={ edition }>
                { edition =>
                    <Formik initialValues={ edition } onSubmit={ handleSubmit }>
                        <Form className={ spacing.vertical }>
                            <EditionForm />
                        </Form>
                    </Formik>
                }
            </Async>
        </Container>
    </Page>;
}
