"use client";

import { Box, Fieldset, Flex, Stack } from "@mantine/core";
import AttributesTable from "@/app/module-editor/[moduleId]/components/shared/AttributesTable/AttributesTable";
import CreateAttributeButton from "@/app/module-editor/[moduleId]/components/shared/CreateAttributeButton/CreateAttributeButton";
import ModuleAttributesEditor from "@/app/module-editor/[moduleId]/components/shared/ModuleAttributesEditor/ModuleAttributesEditor";
import ModuleCommonInfoEditor from "@/app/module-editor/[moduleId]/components/shared/ModuleCommonInfoEditor/ModuleCommonInfoEditor";
import { useModuleEditorContext } from "@/app/module-editor/[moduleId]/contexts/ModuleEditorContext";
import PageBlock from "@/components/layout/PageBlock/PageBlock";

const PageBody = () => {
    const { module } = useModuleEditorContext();

    if (!module) return;

    return (
        <Stack h={"100%"}>
            <PageBlock
                style={{ flex: 1, minHeight: 0 }}
                fullScreenMobile>
                <Flex
                    w={"100%"}
                    h={"100%"}
                    flex={3}
                    style={{ overflow: "auto" }}
                    gap={"md"}>
                    <Fieldset
                        flex={1}
                        legend={"Атрибуты"}>
                        <Flex
                            direction={"column"}
                            h={"100%"}
                            gap={"xs"}>
                            <Box style={{ flex: 1, minHeight: 0 }}>
                                <AttributesTable />
                            </Box>
                            <CreateAttributeButton />
                        </Flex>
                    </Fieldset>
                    <Flex
                        gap={"xs"}
                        flex={2}
                        direction={"column"}>
                        <Fieldset
                            flex={1}
                            legend={"Общие данные модуля"}>
                            {module && <ModuleCommonInfoEditor />}
                        </Fieldset>
                        <Fieldset
                            flex={3}
                            legend={"Атрибуты модуля"}>
                            <ModuleAttributesEditor />
                        </Fieldset>
                    </Flex>
                </Flex>
            </PageBlock>
        </Stack>
    );
};

export default PageBody;
