"use client" import Image from "next/image" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Calendar } from "@/components/ui/calendar" import { Input } from "@/components/ui/input" import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Textarea } from "@/components/ui/textarea" import { cn } from "@/lib/utils" import { SelectProps } from "@radix-ui/react-select" import { format } from "date-fns" import { CalendarIcon, Upload } from "lucide-react" import { InputHTMLAttributes, TextareaHTMLAttributes, useEffect, useRef, useState } from "react" type FormInputProps = InputHTMLAttributes & { title?: string hideIfEmpty?: boolean isRequired?: boolean } export function FormInput({ title, hideIfEmpty = false, isRequired = false, ...props }: FormInputProps) { const isEmpty = (!props.defaultValue || props.defaultValue.toString().trim() === "") && !props.value if (hideIfEmpty && isEmpty) { return null } return ( ) } type FormTextareaProps = TextareaHTMLAttributes & { title?: string hideIfEmpty?: boolean isRequired?: boolean } export function FormTextarea({ title, hideIfEmpty = false, isRequired = false, ...props }: FormTextareaProps) { const textareaRef = useRef(null) const isEmpty = (!props.defaultValue || props.defaultValue.toString().trim() === "") && !props.value useEffect(() => { const textarea = textareaRef.current if (!textarea) return const resize = () => { textarea.style.height = "auto" textarea.style.height = `${textarea.scrollHeight + 5}px` } resize() // initial resize textarea.addEventListener("input", resize) return () => textarea.removeEventListener("input", resize) }, [props.value, props.defaultValue]) if (hideIfEmpty && isEmpty) { return null } return (