"use client"; import { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { MessageSquarePlus, Trash2, Pencil, Check, X } from "lucide-react"; import { loadCannedMessages, saveCannedMessage, deleteCannedMessage, type CannedMessage, } from "@/lib/canned-messages-store"; import { MAX_CANNED_MESSAGES, MAX_CANNED_MESSAGE_LENGTH } from "@/lib/limits"; import { useAuth } from "@/lib/auth/context"; interface CannedMessagesPanelProps { compact?: boolean; onSelect?: (content: string) => void; } export function CannedMessagesPanel({ compact, onSelect }: CannedMessagesPanelProps) { const { user } = useAuth(); const [messages, setMessages] = useState([]); const [editing, setEditing] = useState(null); const [editTitle, setEditTitle] = useState(""); const [editContent, setEditContent] = useState(""); const [showNew, setShowNew] = useState(false); const [newTitle, setNewTitle] = useState(""); const [newContent, setNewContent] = useState(""); const [error, setError] = useState(""); const refresh = async () => { setMessages(await loadCannedMessages(user?.id)); }; useEffect(() => { refresh(); }, [user?.id]); const startEdit = (msg: CannedMessage) => { setEditing(msg.id); setEditTitle(msg.title); setEditContent(msg.content); }; const saveEdit = async () => { const { error: err } = await saveCannedMessage( { id: editing!, title: editTitle, content: editContent }, user?.id ); if (err) setError(err); else { setEditing(null); setError(""); await refresh(); } }; const handleCreate = async () => { const { error: err } = await saveCannedMessage( { title: newTitle, content: newContent }, user?.id ); if (err) setError(err); else { setShowNew(false); setNewTitle(""); setNewContent(""); setError(""); await refresh(); } }; const handleDelete = async (id: string) => { await deleteCannedMessage(id, user?.id); await refresh(); }; if (compact) { return (
{messages.map((msg) => ( ))} {messages.length === 0 && (

No quick replies — add them in Profile

)}
); } return (
Quick Replies {messages.length}/{MAX_CANNED_MESSAGES}

Save addresses, directions, hosting notes — tap to insert while messaging.

{messages.map((msg) => (
{editing === msg.id ? ( <> setEditTitle(e.target.value)} placeholder="Label (e.g. Address)" />