{"id":42,"date":"2025-11-28T11:37:14","date_gmt":"2025-11-28T14:37:14","guid":{"rendered":"https:\/\/sprayway.com.br\/?page_id=42"},"modified":"2025-11-28T13:06:25","modified_gmt":"2025-11-28T16:06:25","slug":"gestao-sprayway","status":"publish","type":"page","link":"https:\/\/sprayway.com.br\/index.php\/gestao-sprayway\/","title":{"rendered":"Gest\u00e3o SprayWay"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"42\" class=\"elementor elementor-42\">\n\t\t\t\t<div class=\"elementor-element elementor-element-3147aca e-flex e-con-boxed e-con e-parent\" data-id=\"3147aca\" data-element_type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-5e3e208 elementor-widget elementor-widget-html\" data-id=\"5e3e208\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t\t<!DOCTYPE html>\r\n<html lang=\"pt-BR\">\r\n<head>\r\n    <meta charset=\"UTF-8\">\r\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n    <title>Acesso Sprayway<\/title>\r\n    <script src=\"https:\/\/cdn.tailwindcss.com\"><\/script>\r\n    <link href=\"https:\/\/fonts.googleapis.com\/css2?family=Inter:wght@300;400;500;600;700&display=swap\" rel=\"stylesheet\">\r\n    \r\n    <script type=\"importmap\">\r\n    {\r\n        \"imports\": {\r\n            \"react\": \"https:\/\/esm.sh\/react@18.2.0\",\r\n            \"react-dom\/client\": \"https:\/\/esm.sh\/react-dom@18.2.0\/client\",\r\n            \"lucide-react\": \"https:\/\/esm.sh\/lucide-react@0.263.1\",\r\n            \"firebase\/app\": \"https:\/\/www.gstatic.com\/firebasejs\/10.7.1\/firebase-app.js\",\r\n            \"firebase\/auth\": \"https:\/\/www.gstatic.com\/firebasejs\/10.7.1\/firebase-auth.js\",\r\n            \"firebase\/firestore\": \"https:\/\/www.gstatic.com\/firebasejs\/10.7.1\/firebase-firestore.js\"\r\n        }\r\n    }\r\n    <\/script>\r\n    <script type=\"module\" src=\"https:\/\/esm.sh\/run\" defer><\/script>\r\n    <script src=\"https:\/\/unpkg.com\/@babel\/standalone\/babel.min.js\"><\/script>\r\n\r\n    <style>\r\n        body { font-family: 'Inter', sans-serif; }\r\n        \/* Reset agressivo para evitar conflitos com tema WP *\/\r\n        #root button { border: none !important; outline: none !important; box-shadow: none !important; background-image: none !important; }\r\n        #root input { background-image: none !important; box-shadow: none !important; }\r\n        \r\n        \/* Classe auxiliar para for\u00e7ar o padding *\/\r\n        .force-padding-left {\r\n            padding-left: 3rem !important; \/* 48px *\/\r\n        }\r\n    <\/style>\r\n<\/head>\r\n<body class=\"bg-white text-gray-800\">\r\n    <div id=\"root\"><\/div>\r\n\r\n    <script type=\"text\/babel\" data-type=\"module\">\r\n        import React, { useState, useEffect } from 'react';\r\n        import { createRoot } from 'react-dom\/client';\r\n        import { getAuth, signInWithEmailAndPassword, onAuthStateChanged, signOut } from 'firebase\/auth';\r\n        import { getFirestore, doc, getDoc, setDoc, serverTimestamp } from 'firebase\/firestore';\r\n        import { initializeApp } from 'firebase\/app';\r\n        import { User, Lock, Building2, Loader2, AlertCircle, LogOut, CheckCircle2 } from 'lucide-react';\r\n\r\n        \/\/ --- CONFIGURA\u00c7\u00c3O ---\r\n        \/\/ URL da p\u00e1gina Administrativa (Destino do Admin)\r\n        const URL_DASHBOARD_ADM = \"https:\/\/sprayway.com.br\/index.php\/sprayway-administrativo\/\";\r\n\r\n        const firebaseConfig = {\r\n            apiKey: \"AIzaSyBfgzzmWL_482x8NWF0sDw5O4hy2N-cX4c\",\r\n            authDomain: \"sprayway-60922.firebaseapp.com\",\r\n            projectId: \"sprayway-60922\",\r\n            storageBucket: \"sprayway-60922.firebasestorage.app\",\r\n            messagingSenderId: \"657452969818\",\r\n            appId: \"1:657452969818:web:7d4ea2d408f655f9a40d63\"\r\n        };\r\n\r\n        const app = initializeApp(firebaseConfig);\r\n        const auth = getAuth(app);\r\n        const db = getFirestore(app);\r\n\r\n        \/\/ Seus emails de super admin para garantir acesso\r\n        const SUPER_ADMINS = ['andre@get84.com.br'];\r\n\r\n        function App() {\r\n            const [user, setUser] = useState(null);\r\n            const [view, setView] = useState('login'); \r\n            const [loading, setLoading] = useState(true);\r\n\r\n            useEffect(() => {\r\n                const unsubscribe = onAuthStateChanged(auth, async (currentUser) => {\r\n                    if (currentUser) {\r\n                        try {\r\n                            \/\/ Verifica o papel no banco de dados\r\n                            let role = 'client'; \/\/ Padr\u00e3o\r\n                            const userRef = doc(db, 'users', currentUser.uid);\r\n                            const snap = await getDoc(userRef);\r\n\r\n                            if (snap.exists()) {\r\n                                \/\/ Se j\u00e1 tem perfil, usa o que est\u00e1 l\u00e1\r\n                                role = snap.data().role || 'client';\r\n                            } else {\r\n                                \/\/ --- REGRA DE OURO ---\r\n                                \/\/ Se logou mas N\u00c3O tem perfil, assumimos que foi criado no painel do Firebase.\r\n                                \/\/ Criamos o perfil de ADMIN automaticamente agora.\r\n                                console.log(\"Usu\u00e1rio sem perfil detectado. Criando como Admin.\");\r\n                                await setDoc(userRef, {\r\n                                    email: currentUser.email,\r\n                                    role: 'admin', \/\/ FOR\u00c7A ADMIN\r\n                                    name: 'Admin Firebase',\r\n                                    createdAt: serverTimestamp()\r\n                                });\r\n                                role = 'admin';\r\n                            }\r\n\r\n                            \/\/ Bypass manual para seu email\r\n                            if (SUPER_ADMINS.includes(currentUser.email)) role = 'admin';\r\n\r\n                            \/\/ REDIRECIONAMENTO\r\n                            if (role === 'admin') {\r\n                                window.location.href = URL_DASHBOARD_ADM;\r\n                            } else {\r\n                                setUser(currentUser);\r\n                                setView('client_dashboard');\r\n                                setLoading(false);\r\n                            }\r\n\r\n                        } catch (error) {\r\n                            console.error(\"Erro ao verificar usu\u00e1rio:\", error);\r\n                            \/\/ Em caso de erro, desloga por seguran\u00e7a\r\n                            await signOut(auth);\r\n                            setLoading(false);\r\n                        }\r\n                    } else {\r\n                        setUser(null);\r\n                        setView('login');\r\n                        setLoading(false);\r\n                    }\r\n                });\r\n                return () => unsubscribe();\r\n            }, []);\r\n\r\n            if (loading) return <div className=\"h-screen flex items-center justify-center\"><Loader2 className=\"w-8 h-8 text-[#f26522] animate-spin\" \/><\/div>;\r\n\r\n            return view === 'login' ? <LoginPage \/> : <ClientDashboard user={user} \/>;\r\n        }\r\n\r\n        function LoginPage() {\r\n            const [role, setRole] = useState('client');\r\n            const [email, setEmail] = useState('');\r\n            const [password, setPassword] = useState('');\r\n            const [error, setError] = useState('');\r\n            const [loading, setLoading] = useState(false);\r\n\r\n            const handleLogin = async (e) => {\r\n                e.preventDefault();\r\n                setError('');\r\n                setLoading(true);\r\n                try {\r\n                    await signInWithEmailAndPassword(auth, email, password);\r\n                    \/\/ O redirecionamento \u00e9 autom\u00e1tico no useEffect do App\r\n                } catch (err) {\r\n                    console.error(err);\r\n                    setError('E-mail ou senha incorretos.');\r\n                    setLoading(false);\r\n                }\r\n            };\r\n\r\n            return (\r\n                <div className=\"min-h-screen flex flex-col md:flex-row bg-white font-sans\">\r\n                    {\/* Esquerda *\/}\r\n                    <div className=\"md:w-1\/2 bg-zinc-900 text-white p-8 md:p-16 flex flex-col justify-center relative overflow-hidden\">\r\n                        <div className=\"z-10 relative space-y-6\">\r\n                            <div className=\"flex items-center gap-2\"><span className=\"font-bold text-2xl tracking-tighter\">SPRAYWAY <span className=\"text-[#f26522]\">PINTURAS<\/span><\/span><\/div>\r\n                            <h1 className=\"text-4xl md:text-5xl font-bold leading-tight\">Gest\u00e3o profissional <br\/> para sua <span className=\"text-[#f26522]\">obra<\/span>.<\/h1>\r\n                            <p className=\"text-gray-400 text-lg max-w-md\">Acesso exclusivo para gest\u00e3o de or\u00e7amentos e obras.<\/p>\r\n                        <\/div>\r\n                        <div className=\"absolute bottom-0 right-0 w-96 h-96 bg-[#f26522] rounded-full blur-[120px] opacity-20 translate-x-1\/3 translate-y-1\/3\"><\/div>\r\n                        <div className=\"absolute bottom-8 left-16 text-sm text-gray-500 z-10\">\u00a9 {new Date().getFullYear()} Sprayway Pinturas.<\/div>\r\n                    <\/div>\r\n\r\n                    {\/* Direita *\/}\r\n                    <div className=\"md:w-1\/2 flex items-center justify-center p-8\">\r\n                        <div className=\"w-full max-w-md space-y-8\">\r\n                            <div className=\"text-center space-y-2\">\r\n                                <h2 className=\"text-2xl font-bold text-gray-900\">Acesse sua conta<\/h2>\r\n                                <p className=\"text-gray-500 text-sm\">Bem-vindo ao portal<\/p>\r\n                            <\/div>\r\n\r\n                            <div className=\"flex gap-3 bg-gray-50 p-1 rounded-lg\">\r\n                                <button type=\"button\" onClick={() => setRole('client')} className={`flex-1 py-2.5 text-sm font-medium rounded-md transition-all flex items-center justify-center gap-2 ${role === 'client' ? 'bg-white shadow text-gray-900' : 'text-gray-500 hover:text-gray-700'}`}><User className=\"w-4 h-4\" \/> Sou Cliente<\/button>\r\n                                <button type=\"button\" onClick={() => setRole('admin')} className={`flex-1 py-2.5 text-sm font-medium rounded-md transition-all flex items-center justify-center gap-2 ${role === 'admin' ? 'bg-white shadow text-[#f26522]' : 'text-gray-500 hover:text-gray-700'}`}><Building2 className=\"w-4 h-4\" \/> Administrativo<\/button>\r\n                            <\/div>\r\n\r\n                            <form onSubmit={handleLogin} className=\"space-y-5\">\r\n                                <div>\r\n                                    <label className=\"text-xs font-medium text-gray-700 mb-1 block\">E-mail<\/label>\r\n                                    <div className=\"relative\">\r\n                                        <div className=\"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none h-full\"><User className=\"h-5 w-5 text-gray-400\" \/><\/div>\r\n                                        {\/* CORRE\u00c7\u00c3O DE SOBREPOSI\u00c7\u00c3O: classe force-padding-left *\/}\r\n                                        <input \r\n                                            type=\"email\" \r\n                                            required \r\n                                            className=\"force-padding-left block w-full pr-3 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-[#f26522] focus:border-[#f26522] outline-none transition-all\" \r\n                                            placeholder=\"seu@email.com\" \r\n                                            value={email} \r\n                                            onChange={e => setEmail(e.target.value)} \r\n                                        \/>\r\n                                    <\/div>\r\n                                <\/div>\r\n                                <div>\r\n                                    <label className=\"text-xs font-medium text-gray-700 mb-1 block\">Senha<\/label>\r\n                                    <div className=\"relative\">\r\n                                        <div className=\"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none h-full\"><Lock className=\"h-5 w-5 text-gray-400\" \/><\/div>\r\n                                        {\/* CORRE\u00c7\u00c3O DE SOBREPOSI\u00c7\u00c3O: classe force-padding-left *\/}\r\n                                        <input \r\n                                            type=\"password\" \r\n                                            required \r\n                                            className=\"force-padding-left block w-full pr-3 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-[#f26522] focus:border-[#f26522] outline-none transition-all\" \r\n                                            placeholder=\"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\" \r\n                                            value={password} \r\n                                            onChange={e => setPassword(e.target.value)} \r\n                                        \/>\r\n                                    <\/div>\r\n                                <\/div>\r\n\r\n                                {error && <div className=\"p-3 bg-red-50 text-red-600 text-sm rounded-lg flex items-center gap-2\"><AlertCircle className=\"w-4 h-4\" \/>{error}<\/div>}\r\n\r\n                                <button type=\"submit\" disabled={loading} className=\"w-full py-3 px-4 bg-[#f26522] hover:bg-[#d9561b] text-white font-bold rounded-lg transition-colors flex justify-center items-center\">{loading ? <Loader2 className=\"animate-spin w-5 h-5\" \/> : 'Entrar no Sistema'}<\/button>\r\n                            <\/form>\r\n                        <\/div>\r\n                    <\/div>\r\n                <\/div>\r\n            );\r\n        }\r\n\r\n        function ClientDashboard({ user }) {\r\n            return (\r\n                <div className=\"min-h-screen bg-gray-50 font-sans\">\r\n                    <nav className=\"bg-white shadow-sm border-b border-gray-100\">\r\n                        <div className=\"max-w-7xl mx-auto px-4 h-16 flex justify-between items-center\">\r\n                            <span className=\"font-bold text-xl tracking-tight\">SPRAYWAY <span className=\"text-[#f26522]\">CLIENTE<\/span><\/span>\r\n                            <div className=\"flex items-center gap-4\"><span className=\"text-sm text-gray-500 hidden md:block\">{user.email}<\/span><button onClick={() => signOut(auth)} className=\"text-gray-400 hover:text-red-500\"><LogOut className=\"w-5 h-5\" \/><\/button><\/div>\r\n                        <\/div>\r\n                    <\/nav>\r\n                    <main className=\"max-w-7xl mx-auto p-6 md:p-12\">\r\n                        <div className=\"bg-white rounded-xl shadow-sm border border-gray-100 p-12 text-center\">\r\n                            <div className=\"w-20 h-20 bg-blue-50 text-blue-600 rounded-full flex items-center justify-center mx-auto mb-6\"><User className=\"w-10 h-10\" \/><\/div>\r\n                            <h2 className=\"text-2xl font-bold text-gray-900 mb-2\">Bem-vindo \u00e0 sua \u00c1rea Exclusiva<\/h2>\r\n                            <p className=\"text-gray-500 max-w-lg mx-auto mb-8\">Esta \u00e1rea \u00e9 onde voc\u00ea visualizar\u00e1 o status das suas obras, aprovar\u00e1 or\u00e7amentos e baixar\u00e1 notas fiscais.<\/p>\r\n                            <div className=\"inline-flex items-center px-4 py-2 rounded-full bg-green-50 text-green-700 text-sm font-medium border border-green-100\"><CheckCircle2 className=\"w-4 h-4 mr-2\" \/> Conta ativa e verificada<\/div>\r\n                        <\/div>\r\n                    <\/main>\r\n                <\/div>\r\n            );\r\n        }\r\n\r\n        const root = createRoot(document.getElementById('root'));\r\n        root.render(<App \/>);\r\n    <\/script>\r\n<\/body>\r\n<\/html>\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Acesso Sprayway<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"elementor_canvas","meta":{"footnotes":""},"class_list":["post-42","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/sprayway.com.br\/index.php\/wp-json\/wp\/v2\/pages\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sprayway.com.br\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sprayway.com.br\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sprayway.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sprayway.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":25,"href":"https:\/\/sprayway.com.br\/index.php\/wp-json\/wp\/v2\/pages\/42\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/sprayway.com.br\/index.php\/wp-json\/wp\/v2\/pages\/42\/revisions\/115"}],"wp:attachment":[{"href":"https:\/\/sprayway.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}