"use client";

import { useState, useTransition } from "react";
import { updatePrivateProfile } from "@/lib/actions/profile";

export function PrivacyToggle({ initialIsPrivate }: { initialIsPrivate: boolean }) {
  const [isPrivate, setIsPrivate] = useState(initialIsPrivate);
  const [, startTransition] = useTransition();

  return (
    <label className="flex items-center gap-2 text-sm text-charcoal">
      <input
        type="checkbox"
        checked={isPrivate}
        onChange={() => {
          const next = !isPrivate;
          setIsPrivate(next);
          startTransition(() => {
            updatePrivateProfile(next);
          });
        }}
        className="h-4 w-4 accent-terracotta"
      />
      Private profile (hides folders from other users)
    </label>
  );
}
