// * Packages import { PlusIcon } from "lucide-react"; import { VariantProps } from "class-variance-authority"; // * Components shadcn import { Button, buttonVariants } from "@/components/ui/button"; // * Other import useTrans from "@/hooks/use-translations"; import { ConfigInternalField, DynamicInternalField, } from "@/back/types/dynamic-pages"; type AddNewFieldBtnProps = { array: ConfigInternalField[] | DynamicInternalField[] | undefined; variant?: VariantProps["variant"]; limitMax?: number | undefined; onClick: () => void; }; // Get a button with some informations. export default function AddNewFieldBtn({ array = [], variant = "default", limitMax, onClick, }: AddNewFieldBtnProps) { // Translations. const transNoMoreChildren = useTrans("back.no_more_children"); const transNewField = useTrans("back.new_field"); const transEmptyWarning = useTrans("back.empty_warning"); const transEntriesCount = useTrans("back.entries_count", { params: { length: String(array?.length ?? 0), }, choice: (array?.length ?? 0) > 1 ? 2 : 1, }); return (
{/* Check if the limit is achieved */} {limitMax && array.length >= limitMax ? (

{transNoMoreChildren}

) : ( )} {/* Indicate the current number of elements. */}

{(array?.length ?? 0) > 0 ? transEntriesCount : transEmptyWarning}

); }