import { Box, Button, ExternalLinkIcon, Flex, FlexProps, MetaButton, MetaTheme, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, Select, useDisclosure, VStack, } from '@metafam/ds'; import { Maybe } from '@metafam/utils'; import { GuildFragment, Player } from 'graphql/autogen/types'; import React, { ChangeEvent, forwardRef, ForwardRefExoticComponent, JSXElementConstructor, ReactElement, RefAttributes, useCallback, useEffect, useState, } from 'react'; import { BoxMetadata, BoxType, BoxTypes, DisplayOutput } from 'utils/boxTypes'; import { CustomTextSectionMetadata } from './CustomTextSection'; import { EmbeddedUrlMetadata } from './EmbeddedUrlSection'; export type AddBoxComponent = FlexProps & { player?: Player; guild?: GuildFragment; boxes: Array; onAddBox: (arg0: BoxType, arg1: BoxMetadata) => void; previewComponent: DisplayOutput; }; export type AddBoxReference = ForwardRefExoticComponent< Omit & RefAttributes >; export type AddBoxOutput = ( props: AddBoxComponent, ) => ReactElement>; export type AddBoxElement = ReturnType; export const AddBoxSection = forwardRef( ( { player, guild, boxes = [], onAddBox, previewComponent: Preview, ...props }, ref, ) => { const { isOpen, onOpen, onClose } = useDisclosure(); const [type, setType] = useState>(null); const [metadata, setMetadata] = useState({}); const selectBoxType = useCallback( ({ target: { value: boxId } }: ChangeEvent) => setType(boxId as BoxType), [], ); const addSection = useCallback(() => { if (!type) return; onAddBox(type, metadata); onClose(); }, [type, metadata, onAddBox, onClose]); useEffect(() => { setMetadata({}); setType(null); }, [isOpen]); return ( Add New Block {type && ( )} {type && ( )} Create a Custom Block ); }, ); export const EditMetadata: React.FC<{ type: BoxType; metadata: BoxMetadata; setMetadata: React.Dispatch>; }> = ({ type, ...props }) => { switch (type) { case BoxTypes.EMBEDDED_URL: return ; case BoxTypes.CUSTOM_TEXT: return ; default: return null; } };