import { useState, useEffect } from "react";
import { Send, Check, CheckCheck, Bell, Mail, Smartphone, Megaphone, FileText, CreditCard } from "lucide-react";
interface Message {
id: string;
sender: "customer" | "business";
senderName: string;
text: string;
timestamp: string;
read: boolean;
}
interface NotificationCategory {
email: boolean;
sms: boolean;
push: boolean;
}
interface NotificationPreferences {
appointmentReminders: NotificationCategory;
vaccinationAlerts: NotificationCategory;
promotional: NotificationCategory;
reportCards: NotificationCategory;
invoiceReceipts: NotificationCategory;
}
interface Props {
readOnly: boolean;
}
export function Communication({ readOnly }: Props) {
const [tab, setTab] = useState<"messages" | "notifications">("messages");
return (
{tab === "messages" &&
}
{tab === "notifications" &&
}
);
}
function MessageThread({ readOnly }: { readOnly: boolean }) {
const [messages, setMessages] = useState([]);
const [newMessage, setNewMessage] = useState("");
const [businessName, setBusinessName] = useState("Business");
useEffect(() => {
async function fetchBranding() {
try {
const response = await fetch("/api/branding");
if (response.ok) {
const data = await response.json();
setBusinessName(data.businessName || data.name || "Business");
}
} catch {
setBusinessName("Business");
}
}
fetchBranding();
}, []);
const handleSend = () => {
if (!newMessage.trim() || readOnly) return;
const msg: Message = {
id: `m-${Date.now()}`,
sender: "customer",
senderName: "You",
text: newMessage.trim(),
timestamp: new Date().toISOString(),
read: false,
};
setMessages([...messages, msg]);
setNewMessage("");
};
return (
{businessName}
Usually replies within a few hours
{messages.length === 0 ? (
No messages yet
) : (
messages.map(msg => (
{msg.text}
{new Date(msg.timestamp).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" })}
{msg.sender === "customer" && (
msg.read
?
:
)}
))
)}
{!readOnly && (
setNewMessage(e.target.value)}
onKeyDown={e => e.key === "Enter" && handleSend()}
placeholder="Type a message..."
className="flex-1 border border-stone-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-(--color-accent)/30 focus:border-(--color-accent)"
/>
)}
);
}
function NotificationPreferences({ readOnly }: { readOnly: boolean }) {
const [prefs, setPrefs] = useState({
appointmentReminders: { email: true, sms: true, push: true },
vaccinationAlerts: { email: true, sms: false, push: true },
promotional: { email: false, sms: false, push: false },
reportCards: { email: true, sms: false, push: true },
invoiceReceipts: { email: true, sms: false, push: false },
});
type PrefKey = keyof NotificationPreferences;
type ChannelKey = "email" | "sms" | "push";
const toggle = (category: PrefKey, channel: ChannelKey) => {
if (readOnly) return;
setPrefs(prev => ({
...prev,
[category]: {
...prev[category],
[channel]: !prev[category][channel],
},
}));
};
const categories: { key: PrefKey; label: string; desc: string; icon: typeof Bell }[] = [
{ key: "appointmentReminders", label: "Appointment Reminders", desc: "Upcoming appointment notifications", icon: Bell },
{ key: "vaccinationAlerts", label: "Vaccination Alerts", desc: "Expiration and renewal reminders", icon: FileText },
{ key: "promotional", label: "Promotions & Offers", desc: "Deals and seasonal specials", icon: Megaphone },
{ key: "reportCards", label: "Report Cards", desc: "Grooming report card delivery", icon: FileText },
{ key: "invoiceReceipts", label: "Invoice & Receipts", desc: "Payment confirmations", icon: CreditCard },
];
const channels: { key: ChannelKey; label: string; icon: typeof Mail }[] = [
{ key: "email", label: "Email", icon: Mail },
{ key: "sms", label: "SMS", icon: Smartphone },
{ key: "push", label: "Push", icon: Bell },
];
return (
| Category |
{channels.map(ch => (
{ch.label}
|
))}
{categories.map(cat => (
|
{cat.label}
{cat.desc}
|
{channels.map(ch => (
|
))}
))}
);
}
export default Communication;