"use client"; import { useState, useEffect, ChangeEvent } from "react"; import { useRouter } from "next/navigation"; import Layout from "@/components/layout/layout"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Save, Send, Key, MessageSquare, Shield, Globe, Wallet } from "lucide-react"; import { apiRequest } from "@/lib/api"; import { toast, Toaster } from "sonner"; import BroadcastDialog from "@/components/modals/broadcast-dialog"; import Dashboard from "@/components/dashboard/dashboard"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; const SHIPPING_REGIONS = [ { value: "UK", label: "United Kingdom", emoji: "πŸ‡¬πŸ‡§" }, { value: "EU", label: "European Union", emoji: "πŸ‡ͺπŸ‡Ί" }, { value: "USA", label: "United States", emoji: "πŸ‡ΊπŸ‡Έ" }, { value: "WW", label: "Worldwide", emoji: "🌍" }, ] as const; interface Storefront { pgpKey: string; welcomeMessage: string; telegramToken: string; shipsFrom: typeof SHIPPING_REGIONS[number]["value"]; shipsTo: typeof SHIPPING_REGIONS[number]["value"]; storePolicy: string; isEnabled: boolean; wallets: { bitcoin?: string; litecoin: string; monero?: string; }; enabledWallets: { bitcoin: boolean; litecoin: boolean; monero: boolean; }; } const WALLET_OPTIONS = [ { id: 'bitcoin', name: 'Bitcoin', emoji: 'β‚Ώ', placeholder: 'Your BTC address', disabled: true, comingSoon: true }, { id: 'litecoin', name: 'Litecoin', emoji: 'Ł', placeholder: 'Your LTC address', disabled: false, comingSoon: false }, { id: 'monero', name: 'Monero', emoji: 'M', placeholder: 'Your XMR address', disabled: true, comingSoon: true }, ] as const; export default function StorefrontPage() { const router = useRouter(); const [storefront, setStorefront] = useState({ pgpKey: "", welcomeMessage: "", telegramToken: "", shipsFrom: "UK", shipsTo: "WW", storePolicy: "", isEnabled: false, wallets: { bitcoin: '', litecoin: '', monero: '' }, enabledWallets: { bitcoin: false, litecoin: false, monero: false } }); const [broadcastOpen, setBroadcastOpen] = useState(false); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); useEffect(() => { const authToken = document.cookie .split("; ") .find((row) => row.startsWith("Authorization=")) ?.split("=")[1]; if (!authToken) { router.push("/login"); return; } const fetchStorefront = async () => { try { setLoading(true); const data = await apiRequest("/storefront"); setStorefront({ pgpKey: data.pgpKey || "", welcomeMessage: data.welcomeMessage || "", telegramToken: data.telegramToken || "", shipsFrom: data.shipsFrom || "UK", shipsTo: data.shipsTo || "WW", storePolicy: data.storePolicy || "", isEnabled: data.isEnabled || false, wallets: { bitcoin: data.wallets?.bitcoin || '', litecoin: data.wallets?.litecoin || '', monero: data.wallets?.monero || '' }, enabledWallets: { bitcoin: data.enabledWallets?.bitcoin || false, litecoin: data.enabledWallets?.litecoin || true, monero: data.enabledWallets?.monero || false } }); } catch (error) { toast.error("Failed to load storefront data."); } finally { setLoading(false); } }; fetchStorefront(); }, []); const handleInputChange = ( e: ChangeEvent ) => { setStorefront(prev => ({ ...prev, [e.target.name]: e.target.value })); }; const saveStorefront = async () => { try { setSaving(true); await apiRequest("/storefront", "PUT", storefront); toast.success("Storefront updated successfully!"); } catch (error) { toast.error("Failed to update storefront."); } finally { setSaving(false); } }; return (

Storefront Settings

setStorefront((prev) => ({ ...prev, isEnabled: checked, })) } /> {storefront.isEnabled ? 'Store Open' : 'Store Closed'}

{storefront.isEnabled ? 'Click to close store' : 'Click to open store'}

{/* Security Settings */}

Security