import { typeboxResolver } from "@hookform/resolvers/typebox";
import { Select, Switch, TextInput } from "@mantine/core";
import { TypeRegistry } from "@sinclair/typebox";
import {
type Static,
StringEnum,
StringIdentifier,
Type,
registerCustomTypeboxKinds
} from "core/utils";
import { ManyToOneRelation, type RelationType, RelationTypes } from "data";
import { type ReactNode, useEffect } from "react";
import { type Control, type FieldValues, type UseFormRegister, useForm } from "react-hook-form";
import { useBknd } from "ui/client";
import { MantineNumberInput } from "ui/components/form/hook-form-mantine/MantineNumberInput";
import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelect";
import { useStepContext } from "ui/components/steps/Steps";
import { ModalBody, ModalFooter, type TCreateModalSchema } from "./CreateModal";
// @todo: check if this could become an issue
registerCustomTypeboxKinds(TypeRegistry);
const Relations: {
type: RelationType;
label: string;
component: (props: ComponentCtx
Many {source} will each have one reference to {target}.
A property
{config.mappedBy || target}_id will be added to{" "}
{source} (which references {target}).
When creating
{source}, a reference to {target} is{" "}
{config.required ? "required" : "optional"}.
{config.sourceCardinality ? (
{source} should not have more than{" "}
{config.sourceCardinality} referencing entr
{config.sourceCardinality === 1 ? "y" : "ies"} to {source}.
) : null}
>
)}
>
);
}
function OneToOne({
register,
control,
data: {
source,
target,
config: { mappedBy, required }
}
}: ComponentCtx) {
return (
<>
A single entry of
{source} will have a reference to{" "}
{target}.
A property
{mappedBy || target}_id will be added to{" "}
{source} (which references {target}).
When creating
{source}, a reference to {target} is{" "}
{required ? "required" : "optional"}.
>
Many
{source} will have many {target}.
A connection table
{table} will be created to store the relations.
>
{source} will have many {target}.
{target} will get additional properties referenceand{" "}
entity_idto make the (polymorphic) reference. {config.targetCardinality ? (
{source} should not have more than{" "}
{config.targetCardinality} reference
{config.targetCardinality === 1 ? "" : "s"} to {target}.
) : null}
>