"use client";
import { useState, useEffect } from 'react';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useToast } from '@/contexts/ToastContext';
// Ícones pré-definidos para seleção
const AVAILABLE_ICONS = [
// Pessoas e Equipe
{ value: 'ri-team-line', label: 'Equipe', category: 'pessoas' },
{ value: 'ri-user-star-line', label: 'Destaque', category: 'pessoas' },
{ value: 'ri-user-follow-line', label: 'Seguir', category: 'pessoas' },
{ value: 'ri-group-line', label: 'Grupo', category: 'pessoas' },
// Segurança
{ value: 'ri-shield-check-line', label: 'Segurança', category: 'segurança' },
{ value: 'ri-shield-star-line', label: 'Proteção Premium', category: 'segurança' },
{ value: 'ri-lock-line', label: 'Cadeado', category: 'segurança' },
{ value: 'ri-hard-hat-line', label: 'Capacete', category: 'segurança' },
// Serviços
{ value: 'ri-service-line', label: 'Atendimento', category: 'serviço' },
{ value: 'ri-customer-service-line', label: 'Suporte', category: 'serviço' },
{ value: 'ri-tools-line', label: 'Ferramentas', category: 'serviço' },
{ value: 'ri-settings-3-line', label: 'Engrenagem', category: 'serviço' },
// Transporte
{ value: 'ri-car-line', label: 'Veículo', category: 'transporte' },
{ value: 'ri-truck-line', label: 'Caminhão', category: 'transporte' },
{ value: 'ri-bus-line', label: 'Ônibus', category: 'transporte' },
{ value: 'ri-motorbike-line', label: 'Moto', category: 'transporte' },
// Documentos
{ value: 'ri-file-list-3-line', label: 'Documentos', category: 'documentos' },
{ value: 'ri-file-text-line', label: 'Arquivo', category: 'documentos' },
{ value: 'ri-clipboard-line', label: 'Prancheta', category: 'documentos' },
{ value: 'ri-contract-line', label: 'Contrato', category: 'documentos' },
// Conquistas
{ value: 'ri-award-line', label: 'Prêmio', category: 'conquista' },
{ value: 'ri-trophy-line', label: 'Troféu', category: 'conquista' },
{ value: 'ri-medal-line', label: 'Medalha', category: 'conquista' },
{ value: 'ri-vip-crown-line', label: 'Coroa', category: 'conquista' },
// Inovação
{ value: 'ri-lightbulb-line', label: 'Ideia', category: 'inovação' },
{ value: 'ri-flashlight-line', label: 'Lanterna', category: 'inovação' },
{ value: 'ri-rocket-line', label: 'Foguete', category: 'inovação' },
{ value: 'ri-flask-line', label: 'Experimento', category: 'inovação' },
// Status
{ value: 'ri-checkbox-circle-line', label: 'Confirmado', category: 'status' },
{ value: 'ri-check-double-line', label: 'Verificado', category: 'status' },
{ value: 'ri-star-line', label: 'Estrela', category: 'status' },
{ value: 'ri-thumb-up-line', label: 'Aprovado', category: 'status' },
// Dados
{ value: 'ri-pie-chart-line', label: 'Gráfico Pizza', category: 'dados' },
{ value: 'ri-bar-chart-line', label: 'Gráfico Barras', category: 'dados' },
{ value: 'ri-line-chart-line', label: 'Gráfico Linha', category: 'dados' },
{ value: 'ri-dashboard-line', label: 'Dashboard', category: 'dados' },
// Performance
{ value: 'ri-speed-line', label: 'Velocidade', category: 'performance' },
{ value: 'ri-timer-line', label: 'Cronômetro', category: 'performance' },
{ value: 'ri-time-line', label: 'Relógio', category: 'performance' },
{ value: 'ri-pulse-line', label: 'Pulso', category: 'performance' },
// Negócios
{ value: 'ri-building-line', label: 'Empresa', category: 'negócios' },
{ value: 'ri-briefcase-line', label: 'Maleta', category: 'negócios' },
{ value: 'ri-money-dollar-circle-line', label: 'Dinheiro', category: 'negócios' },
{ value: 'ri-hand-coin-line', label: 'Pagamento', category: 'negócios' },
// Cálculo
{ value: 'ri-calculator-line', label: 'Calculadora', category: 'cálculo' },
{ value: 'ri-percent-line', label: 'Porcentagem', category: 'cálculo' },
{ value: 'ri-functions', label: 'Funções', category: 'cálculo' },
// Comunicação
{ value: 'ri-message-3-line', label: 'Mensagem', category: 'comunicação' },
{ value: 'ri-chat-3-line', label: 'Chat', category: 'comunicação' },
{ value: 'ri-phone-line', label: 'Telefone', category: 'comunicação' },
{ value: 'ri-mail-line', label: 'Email', category: 'comunicação' },
// Localização
{ value: 'ri-map-pin-line', label: 'Localização', category: 'local' },
{ value: 'ri-navigation-line', label: 'Navegação', category: 'local' },
{ value: 'ri-roadster-line', label: 'Estrada', category: 'local' },
{ value: 'ri-compass-line', label: 'Bússola', category: 'local' },
];
interface IconSelectorProps {
value: string;
onChange: (icon: string) => void;
label: string;
}
function IconSelector({ value, onChange, label }: IconSelectorProps) {
const [isOpen, setIsOpen] = useState(false);
const [search, setSearch] = useState('');
const filteredIcons = AVAILABLE_ICONS.filter(icon =>
icon.label.toLowerCase().includes(search.toLowerCase()) ||
icon.category.toLowerCase().includes(search.toLowerCase())
);
return (
{isOpen && (
{filteredIcons.map((icon) => (
))}
{filteredIcons.length === 0 && (
Nenhum ícone encontrado
)}
)}
);
}
interface ValueItem {
icon: string;
title: string;
description: string;
}
interface AboutContent {
hero: {
title: string;
subtitle: string;
};
history: {
title: string;
subtitle: string;
paragraph1: string;
paragraph2: string;
};
values: {
title: string;
subtitle: string;
items: ValueItem[];
};
}
export default function EditAboutPage() {
const router = useRouter();
const [loading, setLoading] = useState(false);
const [initialLoading, setInitialLoading] = useState(true);
const [activeTab, setActiveTab] = useState('hero');
const { success, error: showError } = useToast();
const scrollToPreview = (sectionId: string) => {
const element = document.getElementById(`preview-${sectionId}`);
if (element) {
element.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
};
const handleTabChange = (tab: string) => {
setActiveTab(tab);
setTimeout(() => scrollToPreview(tab), 100);
};
const [formData, setFormData] = useState({
hero: {
title: 'Sobre a Occto Engenharia',
subtitle: 'Excelência técnica, compromisso e inovação em cada projeto.'
},
history: {
title: 'Nossa História',
subtitle: 'Tradição e Inovação em Engenharia',
paragraph1: 'Com mais de 15 anos de experiência no mercado, a Occto Engenharia se consolidou como referência em soluções técnicas. Nossa equipe multidisciplinar está preparada para atender demandas complexas com excelência e agilidade.',
paragraph2: 'Ao longo dos anos, desenvolvemos projetos que transformaram a realidade de nossos clientes, sempre pautados pela ética, responsabilidade e compromisso com a qualidade.'
},
values: {
title: 'Nossos Valores',
subtitle: 'O que nos move',
items: [
{ icon: 'ri-medal-line', title: 'Qualidade', description: 'Compromisso com a excelência em todos os nossos serviços e entregas.' },
{ icon: 'ri-shake-hands-line', title: 'Transparência', description: 'Comunicação clara e honesta em todas as etapas do projeto.' },
{ icon: 'ri-leaf-line', title: 'Sustentabilidade', description: 'Soluções que respeitam o meio ambiente e as futuras gerações.' }
]
}
});
useEffect(() => {
fetchPageContent();
}, []);
const fetchPageContent = async () => {
try {
const response = await fetch('/api/pages/about');
if (response.ok) {
const data = await response.json();
if (data.content) {
setFormData(prevData => ({
hero: data.content.hero || prevData.hero,
history: data.content.history || prevData.history,
values: data.content.values || prevData.values
}));
}
}
} catch (err) {
console.log('Nenhum conteúdo salvo ainda, usando padrão');
} finally {
setInitialLoading(false);
}
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
try {
const response = await fetch('/api/pages/about', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: formData })
});
if (!response.ok) throw new Error('Erro ao salvar');
success('Conteúdo da página Sobre atualizado com sucesso!');
} catch (err) {
showError('Erro ao salvar alterações');
} finally {
setLoading(false);
}
};
if (initialLoading) {
return (
);
}
return (
<>
{/* Formulário de Edição - Coluna Esquerda 30% */}
Editar Página Sobre
Personalize o conteúdo institucional
{/* Navigation Tabs */}
{/* Preview em Tempo Real - Coluna Direita Grande */}
Preview em Tempo Real
Visualização aproximada da página pública
Ver Página Real
{/* Hero Preview */}
{activeTab === 'hero' && (
{formData.hero.title}
{formData.hero.subtitle}
)}
{/* History Preview */}
{activeTab === 'history' && (
{formData.history.title}
{formData.history.subtitle}
{formData.history.paragraph1}
{formData.history.paragraph2}
)}
{/* Values Preview */}
{activeTab === 'values' && (
{formData.values.title}
{formData.values.subtitle}
{formData.values.items.map((item, index) => (
{item.title}
{item.description}
))}
)}
>
);
}