"use client"; import { useEffect, useState } from "react"; import { Plus } from "lucide-react"; import { collections, SocialError, type Collection } from "@/lib/social"; import { useAuth } from "@/components/auth/auth-provider"; import { CollectionViews } from "@/components/social/collection/collection-views"; export default function MyCollectionsPage() { const { user } = useAuth(); const [list, setList] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); // Inline create form const [showCreate, setShowCreate] = useState(false); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [isPublic, setIsPublic] = useState(true); const [creating, setCreating] = useState(false); useEffect(() => { setLoading(true); collections .mine() .then((r) => setList(r ?? [])) .catch((err) => setError( err instanceof SocialError ? err.message : "Could not load collections.", ), ) .finally(() => setLoading(false)); }, []); async function createOne(e: React.SyntheticEvent) { e.preventDefault(); if (!title.trim()) return; setCreating(true); setError(null); try { const c = await collections.create({ title, description: description || undefined, is_public: isPublic, }); setList((rows) => [c, ...rows]); setTitle(""); setDescription(""); setShowCreate(false); } catch (err) { setError(err instanceof SocialError ? err.message : "Could not create."); } finally { setCreating(false); } } // Effective per-visibility caps from the server (plan default merged with any // admin override). -1 means unlimited (premium default). const pubLimit = user?.limits?.public_collections ?? 5; const privLimit = user?.limits?.private_collections ?? 5; const unlimited = pubLimit < 0 && privLimit < 0; const publicCount = list.filter((c) => c.is_public).length; const privateCount = list.filter((c) => !c.is_public).length; return (

{unlimited ? ( <>Unlimited collections. ) : ( <> {publicCount} / {pubLimit}{" "} public ·{" "} {privateCount} / {privLimit}{" "} private )}

{!showCreate ? ( ) : null}
{showCreate ? (
setTitle(e.target.value)} placeholder="Collection title" maxLength={120} required className="w-full bg-background text-foreground text-base rounded-md border border-border px-3 py-2 outline-none focus-visible:ring-2 focus-visible:ring-primary/40" />