import * as React from "react" import { useFormContext } from "react-hook-form" import { FormField, FormItem, FormControl, FormLabel, FormMessage } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { cn } from "@/lib/utils" import { LinkFormValues } from "./schema" import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip" import { TooltipArrow } from "@radix-ui/react-tooltip" interface UrlInputProps { urlFetched: string | null fetchMetadata: (url: string) => Promise isFetchingUrlMetadata: boolean } export const UrlInput: React.FC = ({ urlFetched, fetchMetadata, isFetchingUrlMetadata }) => { const [isFocused, setIsFocused] = React.useState(false) const form = useFormContext() const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" && form.getValues("url")) { e.preventDefault() fetchMetadata(form.getValues("url")) } } const shouldShowTooltip = isFocused && !form.formState.errors.url && !!form.getValues("url") && !urlFetched return ( ( Url setIsFocused(true)} onBlur={() => setIsFocused(false)} /> Press Enter to fetch metadata )} /> ) }