import React, { useState } from 'react'; import { Settings as SettingsIcon, Truck, Key, Building, Users, Save, Globe, Smartphone, Bell, Shield, FileCheck, ShoppingBag, RefreshCw, AlertCircle, Upload, Palette } from 'lucide-react'; import clsx from 'clsx'; import { useCRM } from '../context/CRMContext'; import { useTheme } from '../context/ThemeContext'; const ThemeSelector = () => { const { theme, setTheme } = useTheme(); return (

Tema do Sistema

{[ { id: 'light', name: 'Simples (Clean)', color: 'bg-slate-50 border-2 border-slate-200', accent: 'bg-blue-600', text: 'Visual limpo e direto.' }, { id: 'ocean', name: 'Complexo (Ocean)', color: 'bg-[#0f172a]', accent: 'bg-cyan-500', text: 'Alta densidade e contraste.' }, { id: 'dark', name: 'Completo (Pro)', color: 'bg-[#0a0a0c]', accent: 'bg-indigo-600', text: 'Interface imersiva padrão.' }, ].map(t => ( ))}
); }; const Settings: React.FC = () => { const { overheadPercent, exchangeRate, settings, updateSettings } = useCRM(); const [activeTab, setActiveTab] = useState<'general' | 'fiscal' | 'marketplaces' | 'logistics' | 'email' | 'notifications'>('general'); // Local state for form, initialized with context settings const [config, setConfig] = useState(settings || { companyName: 'Arbitra System', cnpj: '', ie: '', defaultOverhead: 20, defaultExchange: 5.65, certificateName: '', certificatePassword: '', geminiKey: 'sk-....................', melhorEnvioToken: '', blingToken: '', tinyToken: '', whatsappNumber: '', nfeSerie: '1', nfeNumber: '159', autoSyncSales: true, autoSyncStock: true, smtpHost: '', smtpPort: '587', smtpUser: '', smtpPass: '', electricityCostKwh: 0.90, }); // Sync state when settings load from DB React.useEffect(() => { if (settings) { setConfig(prev => ({ ...prev, ...settings })); } }, [settings]); const handleSave = async () => { try { await updateSettings(config); alert('Configurações salvas com sucesso!'); } catch (error) { console.error(error); alert('Erro ao salvar configurações.'); } }; const tabs = [ { id: 'general', label: 'Geral', icon: Building, description: 'Dados cadastrais' }, { id: 'fiscal', label: 'Fiscal & NFe', icon: FileCheck, description: 'Certificado e tributação' }, { id: 'appearance', label: 'Aparência', icon: Palette, description: 'Temas e Cores' }, { id: 'marketplaces', label: 'Marketplaces', icon: ShoppingBag, description: 'Integrações de vendas' }, { id: 'logistics', label: 'Logística', icon: Truck, description: 'Fretes e entregas' }, { id: 'email', label: 'Email SMTP', icon: Globe, description: 'Configuração de envio' }, { id: 'notifications', label: 'Notificações', icon: Bell, description: 'Alertas e avisos' }, ]; return (

Configurações do Sistema

Gerencie todos os parâmetros fiscais, integrações e regras de negócio.

{/* Denser Sidebar */}
{tabs.map(tab => ( ))}
{/* Content Area - Denser Forms */}
{activeTab === 'general' && (
{/* Section */}

Identificação da Empresa

setConfig({ ...config, cnpj: e.target.value })} placeholder="00.000.000/0000-00" className="w-full bg-black/20 border border-white/10 rounded-lg px-3 py-2 text-sm text-slate-200 focus:border-indigo-500 outline-none transition-all font-mono" />
setConfig({ ...config, ie: e.target.value })} className="w-full bg-black/20 border border-white/10 rounded-lg px-3 py-2 text-sm text-slate-200 focus:border-indigo-500 outline-none transition-all" />
setConfig({ ...config, companyName: e.target.value })} className="w-full bg-black/20 border border-white/10 rounded-lg px-3 py-2 text-sm text-slate-200 focus:border-indigo-500 outline-none transition-all" />
{/* Section */}

Parâmetros Financeiros

R$ setConfig({ ...config, defaultExchange: parseFloat(e.target.value) })} className="w-full bg-black/20 border border-white/10 rounded-lg pl-8 pr-3 py-2 text-sm text-slate-200 focus:border-emerald-500 outline-none transition-all font-mono" />
% setConfig({ ...config, defaultOverhead: parseFloat(e.target.value) })} className="w-full bg-black/20 border border-white/10 rounded-lg px-3 py-2 text-sm text-slate-200 focus:border-indigo-500 outline-none transition-all font-mono" />
R$ setConfig({ ...config, electricityCostKwh: parseFloat(e.target.value) })} className="w-full bg-black/20 border border-white/10 rounded-lg pl-8 pr-3 py-2 text-sm text-slate-200 focus:border-emerald-500 outline-none transition-all font-mono" />
)} {activeTab === 'appearance' && (
)} {activeTab === 'fiscal' && (
{/* Certificate */}

Certificado Digital (A1)

Clique para selecionar o Certificado .PFX

Sua senha será solicitada após o upload

setConfig({ ...config, certificatePassword: e.target.value })} className="w-full bg-black/20 border border-white/10 rounded-lg px-3 py-2 text-sm text-slate-200 focus:border-indigo-500 outline-none transition-all" />
--/--/----
{/* NFe Config */}

Configuração de Emissão (NFe 4.0)

setConfig({ ...config, nfeNumber: e.target.value })} className="w-full bg-black/20 border border-white/10 rounded-lg px-3 py-2 text-sm text-slate-200 focus:border-indigo-500 outline-none transition-all font-mono" />
setConfig({ ...config, nfeSerie: e.target.value })} className="w-full bg-black/20 border border-white/10 rounded-lg px-3 py-2 text-sm text-slate-200 focus:border-indigo-500 outline-none transition-all font-mono" />
)} {activeTab === 'marketplaces' && (
{/* Major Marketplaces */}

Hub de Integração (Mais de 30 canais)

{[ { name: 'Mercado Livre', color: 'bg-yellow-500', status: 'connected', sales: 1240 }, { name: 'Shopee', color: 'bg-orange-600', status: 'error', sales: 0 }, { name: 'Amazon Seller', color: 'bg-slate-800', status: 'disconnected', sales: 0 }, { name: 'Magalu', color: 'bg-blue-600', status: 'disconnected', sales: 0 }, { name: 'Via Varejo', color: 'bg-green-600', status: 'disconnected', sales: 0 }, { name: 'B2W (Americanas)', color: 'bg-red-600', status: 'disconnected', sales: 0 }, { name: 'Shein', color: 'bg-black', status: 'disconnected', sales: 0 }, { name: 'AliExpress', color: 'bg-red-500', status: 'disconnected', sales: 0 }, ].map(mk => (
{mk.name.substring(0, 2)}

{mk.name}

{mk.status === 'connected' &&

● Online

} {mk.status === 'error' &&

● Erro

} {mk.status === 'disconnected' &&

● Offline

}
{/* Toggle Switch Mockup */}
{mk.status === 'connected' ? ( <>

Vendas Hoje

R$ {mk.sales.toLocaleString('pt-BR')}

) : (

Clique para configurar

)}
))}
{/* Custom Sites / E-commerce Platforms */}

Lojas Virtuais & Sites Próprios

{[ { name: 'WooCommerce', color: 'bg-purple-600' }, { name: 'Shopify', color: 'bg-emerald-500' }, { name: 'Nuvemshop', color: 'bg-blue-500' }, { name: 'Vtex', color: 'bg-pink-600' }, { name: 'API Personalizada', color: 'bg-slate-700', isCustom: true }, ].map(platform => (
{platform.isCustom ? : platform.name.substring(0, 1)}
{platform.name}
))}

* Para API Personalizada, consulte a documentação /docs/api-v1

{/* Automation Settings */}

Regras de Sincronização

Importar Pedidos

Baixar vendas novas a cada 5 min.

setConfig({ ...config, autoSyncSales: !config.autoSyncSales })} className="accent-emerald-500 w-4 h-4" />

Atualizar Estoque

Enviar saldo local para os canais.

setConfig({ ...config, autoSyncStock: !config.autoSyncStock })} className="accent-emerald-500 w-4 h-4" />
)} {activeTab === 'logistics' && (

Hubs de Frete

Melhor Envio
Ativo
setConfig({ ...config, melhorEnvioToken: e.target.value })} placeholder="Token de Produção" type="password" className="w-full bg-black/40 border border-white/10 rounded-lg px-3 py-2 text-slate-400 text-xs focus:border-indigo-500 outline-none transition-all font-mono" />
Frenet
Inativo
)}
); }; export default Settings;