<?php
/**
 * Template Service (Barbearia/Salão) - Tema Escuro Premium
 * Template para barbearias e salões de beleza
 */

// Verificar se foi chamado corretamente
if (!defined('BARBERFLOW')) {
    die('Acesso negado');
}

// Variáveis esperadas: $store, $pdo, $currentStoreId, $storeName, $storeType, $logo, $banner, $whatsapp, $address, $city
// Variáveis de cores: $primaryColor, $bgColor, $cardColor, $textColor, $accentColor, $isLightTheme, $textSecondary, $textMuted, $borderColor

// Buscar serviços da loja
try {
    $servicesStmt = $pdo->prepare("SELECT * FROM services WHERE store_id = ? AND is_active = 1 ORDER BY sort_order ASC LIMIT 6");
    $servicesStmt->execute([$currentStoreId]);
    $services = $servicesStmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $services = [];
}

// Buscar profissionais da loja
try {
    $staffStmt = $pdo->prepare("SELECT u.* FROM users u WHERE u.store_id = ? AND u.role IN ('owner', 'barber', 'employee') AND u.is_active = 1 LIMIT 4");
    $staffStmt->execute([$currentStoreId]);
    $staff = $staffStmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $staff = [];
}

// Horário de funcionamento (mock - futuramente buscar do banco)
$workingHours = [
    ['day' => 'Segunda a Sexta', 'hours' => '09:00 - 20:00'],
    ['day' => 'Sábado', 'hours' => '09:00 - 18:00'],
    ['day' => 'Domingo', 'hours' => 'Fechado'],
];
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($storeName); ?> - <?php echo $storeType; ?></title>
<meta name="description" content="<?php echo htmlspecialchars($storeName); ?> - Agende seu horário online. <?php echo $storeType; ?> com os melhores profissionais.">
<meta name="theme-color" content="<?php echo $primaryColor; ?>">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/iconify-icon@1.0.7/dist/iconify-icon.min.js"></script>
<style>
:root {
    --primary: <?php echo $primaryColor; ?>;
    --primary-light: <?php echo $primaryColor; ?>20;
    --accent: <?php echo $accentColor; ?>;
    --bg: <?php echo $bgColor; ?>;
    --bg-card: <?php echo $cardColor; ?>;
    --text: <?php echo $textColor; ?>;
    --text-secondary: <?php echo $textSecondary; ?>;
    --text-muted: <?php echo $textMuted; ?>;
    --border: <?php echo $borderColor; ?>;
    --gradient: linear-gradient(135deg, <?php echo $primaryColor; ?> 0%, <?php echo $accentColor; ?> 100%);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { 
    font-family: 'Inter', sans-serif; 
    background: var(--bg); 
    color: var(--text); 
    line-height: 1.6; 
}

/* Header */
.header {
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 1rem 2rem;
    background: <?php echo $isLightTheme ? 'rgba(255,255,255,0.95)' : 'rgba(10,10,10,0.95)'; ?>;
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header.sticky-header {
    position: fixed;
    top: 0;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
}

.logo iconify-icon {
    font-size: 2rem;
}

.logo img {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: contain;
}

.logo .logo-text {
    color: var(--primary);
}

.header-actions {
    display: flex;
    gap: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s;
    cursor: pointer;
    border: none;
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--gradient);
    color: <?php echo $isLightTheme ? '#FFF' : '#000'; ?>;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px <?php echo $primaryColor; ?>40;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary-light);
}

/* Hero */
.hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    padding: 6rem 2rem 4rem;
    background: var(--bg);
}

.hero-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    align-items: center;
}

.hero-content {
    max-width: 600px;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--primary-light);
    border-radius: 50px;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 1.5rem;
}

.hero h1 span {
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    max-width: 500px;
}

.hero-buttons {
    display: flex;
    gap: 1rem;
}

.hero-image {
    display: flex;
    justify-content: center;
}

.hero-mockup {
    width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 1rem;
    box-shadow: 0 40px 80px rgba(0,0,0,0.3);
}

.mockup-header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.mockup-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.mockup-dot.red { background: #FF5F56; }
.mockup-dot.yellow { background: #FFBD2E; }
.mockup-dot.green { background: #27C93F; }

.mockup-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mockup-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.mockup-card iconify-icon {
    font-size: 1.5rem;
    color: var(--primary);
}

/* Sections */
.section {
    padding: 5rem 2rem;
}

.section-alt {
    background: <?php echo $isLightTheme ? '#F9FAFB' : '#0D0D0D'; ?>;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.section-header {
    text-align: center;
    margin-bottom: 3rem;
}

.section-tag {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--primary-light);
    border-radius: 50px;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.section-title {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
}

.section-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* Services Grid */
.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.service-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    transition: all 0.3s;
}

.service-card:hover {
    border-color: <?php echo $primaryColor; ?>40;
    transform: translateY(-4px);
}

.service-icon {
    width: 50px;
    height: 50px;
    background: var(--primary-light);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.service-icon iconify-icon {
    font-size: 1.5rem;
    color: var(--primary);
}

.service-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.service-duration {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.service-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

/* Staff Grid */
.staff-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.5rem;
}

.staff-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s;
}

.staff-card:hover {
    border-color: <?php echo $primaryColor; ?>40;
}

.staff-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    color: <?php echo $isLightTheme ? '#FFF' : '#000'; ?>;
    margin: 0 auto 1rem;
    overflow: hidden;
}

.staff-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.staff-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.staff-role {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* CTA */
.cta {
    background: var(--gradient);
    padding: 4rem 2rem;
    text-align: center;
}

.cta h2 {
    font-size: 2rem;
    font-weight: 800;
    color: <?php echo $isLightTheme ? '#FFF' : '#000'; ?>;
    margin-bottom: 1rem;
}

.cta p {
    font-size: 1.1rem;
    color: <?php echo $isLightTheme ? 'rgba(255,255,255,0.8)' : 'rgba(0,0,0,0.7)'; ?>;
    margin-bottom: 2rem;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.cta .btn {
    background: <?php echo $isLightTheme ? '#000' : '#FFF'; ?>;
    color: var(--primary);
}

/* Footer */
.footer {
    background: <?php echo $isLightTheme ? '#1F2937' : '#050505'; ?>;
    color: <?php echo $isLightTheme ? '#FFF' : 'var(--text)'; ?>;
    padding: 3rem 2rem 1.5rem;
    border-top: 1px solid var(--border);
}

.footer-grid {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 3rem;
    margin-bottom: 2rem;
}

.footer-brand .logo {
    margin-bottom: 0.5rem;
}

.footer-brand p {
    color: <?php echo $isLightTheme ? 'rgba(255,255,255,0.7)' : 'var(--text-muted)'; ?>;
    font-size: 0.9rem;
    margin-top: 1rem;
    max-width: 300px;
}

.footer-title {
    font-weight: 700;
    margin-bottom: 1rem;
    color: <?php echo $isLightTheme ? '#FFF' : 'var(--text)'; ?>;
}

.footer-info {
    list-style: none;
}

.footer-info li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    color: <?php echo $isLightTheme ? 'rgba(255,255,255,0.7)' : 'var(--text-muted)'; ?>;
    font-size: 0.9rem;
}

.footer-info iconify-icon {
    color: var(--primary);
    font-size: 1.25rem;
}

.footer-bottom {
    max-width: 1200px;
    margin: 0 auto;
    padding-top: 1.5rem;
    border-top: 1px solid <?php echo $isLightTheme ? 'rgba(255,255,255,0.1)' : 'var(--border)'; ?>;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: <?php echo $isLightTheme ? 'rgba(255,255,255,0.5)' : 'var(--text-muted)'; ?>;
}

.powered-by a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

/* WhatsApp Float */
.whatsapp-float {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    background: #25D366;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFF;
    font-size: 2rem;
    text-decoration: none;
    box-shadow: 0 4px 20px rgba(37, 211, 102, 0.4);
    transition: all 0.3s;
    z-index: 1000;
}

.whatsapp-float:hover {
    transform: scale(1.1);
}

/* Responsive */
@media (max-width: 768px) {
    .hero-inner { grid-template-columns: 1fr; text-align: center; }
    .hero h1 { font-size: 2.25rem; }
    .hero p { margin: 0 auto 2rem; }
    .hero-buttons { justify-content: center; flex-wrap: wrap; }
    .hero-mockup { display: none; }
    .footer-grid { grid-template-columns: 1fr; text-align: center; }
    .footer-brand p { margin-left: auto; margin-right: auto; }
    .footer-bottom { flex-direction: column; gap: 1rem; }
    .header-inner { padding: 0 1rem; }
    .header-actions { gap: 0.5rem; }
    .btn { padding: 0.6rem 1rem; font-size: 0.85rem; }
}
</style>
</head>
<body>

<?php
// Configurações do cabeçalho (vindas do storefront_home.php)
$headerSettings = $headerSettings ?? [
    'logo_type' => 'text',
    'logo_text' => $storeName,
    'logo_image' => $logo,
    'show_search' => false,
    'show_cart' => false,
    'show_wishlist' => false,
    'sticky' => true
];
$stickyClass = ($headerSettings['sticky'] ?? true) ? ' sticky-header' : '';
$logoType = $headerSettings['logo_type'] ?? 'text';
$logoImage = !empty($headerSettings['logo_image']) ? $headerSettings['logo_image'] : $logo;
$logoText = !empty($headerSettings['logo_text']) ? $headerSettings['logo_text'] : $storeName;
?>

<!-- Header -->
<header class="header<?php echo $stickyClass; ?>">
    <div class="header-inner">
        <a href="#" class="logo">
            <?php if ($logoType === 'image' || $logoType === 'both'): ?>
                <?php if (!empty($logoImage)): ?>
                    <img src="<?php echo htmlspecialchars($logoImage); ?>" alt="<?php echo htmlspecialchars($logoText); ?>">
                <?php else: ?>
                    <iconify-icon icon="solar:scissors-bold"></iconify-icon>
                <?php endif; ?>
            <?php else: ?>
                <iconify-icon icon="solar:scissors-bold"></iconify-icon>
            <?php endif; ?>
            
            <?php if ($logoType === 'text' || $logoType === 'both'): ?>
                <span class="logo-text"><?php echo htmlspecialchars($logoText); ?></span>
            <?php endif; ?>
        </a>
        <div class="header-actions">
            <a href="#servicos" class="btn btn-outline">Ver Serviços</a>
            <a href="#agendar" class="btn btn-primary">
                <iconify-icon icon="solar:calendar-bold"></iconify-icon>
                Agendar
            </a>
        </div>
    </div>
</header>

<!-- Hero -->
<section class="hero">
    <div class="hero-inner">
        <div class="hero-content">
            <div class="hero-badge">
                <iconify-icon icon="solar:star-bold"></iconify-icon>
                <?php echo $storeType; ?> Premium
            </div>
            <h1>Bem-vindo à <span><?php echo htmlspecialchars($storeName); ?></span></h1>
            <p>Agende seu horário de forma rápida e prática. Profissionais qualificados prontos para te atender.</p>
            <div class="hero-buttons">
                <a href="#agendar" class="btn btn-primary">
                    <iconify-icon icon="solar:calendar-bold"></iconify-icon>
                    Agendar Agora
                </a>
                <?php if ($whatsapp): ?>
                <a href="https://wa.me/55<?php echo preg_replace('/\D/', '', $whatsapp); ?>" target="_blank" class="btn btn-outline">
                    <iconify-icon icon="mdi:whatsapp"></iconify-icon>
                    WhatsApp
                </a>
                <?php endif; ?>
            </div>
        </div>
        <div class="hero-image">
            <div class="hero-mockup">
                <div class="mockup-header">
                    <span class="mockup-dot red"></span>
                    <span class="mockup-dot yellow"></span>
                    <span class="mockup-dot green"></span>
                </div>
                <div class="mockup-content">
                    <div class="mockup-card">
                        <iconify-icon icon="solar:calendar-bold"></iconify-icon>
                        <span>Agendar</span>
                    </div>
                    <div class="mockup-card">
                        <iconify-icon icon="solar:scissors-bold"></iconify-icon>
                        <span>Serviços</span>
                    </div>
                    <div class="mockup-card">
                        <iconify-icon icon="solar:user-bold"></iconify-icon>
                        <span>Profissionais</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Services -->
<section class="section section-alt" id="servicos">
    <div class="container">
        <div class="section-header">
            <span class="section-tag">Nossos Serviços</span>
            <h2 class="section-title">O que oferecemos</h2>
            <p class="section-subtitle">Serviços de qualidade com os melhores profissionais</p>
        </div>
        
        <?php if (empty($services)): ?>
        <p style="text-align: center; color: var(--text-muted);">Nenhum serviço cadastrado ainda.</p>
        <?php else: ?>
        <div class="services-grid">
            <?php foreach ($services as $service): ?>
            <div class="service-card">
                <div class="service-icon">
                    <iconify-icon icon="solar:scissors-bold"></iconify-icon>
                </div>
                <div class="service-name"><?php echo htmlspecialchars($service['name']); ?></div>
                <div class="service-duration">
                    <iconify-icon icon="solar:clock-circle-bold"></iconify-icon>
                    <?php echo $service['duration'] ?? 30; ?> minutos
                </div>
                <div class="service-price">R$ <?php echo number_format($service['price'] ?? 0, 2, ',', '.'); ?></div>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div>
</section>

<!-- Staff -->
<?php if (!empty($staff)): ?>
<section class="section" id="equipe">
    <div class="container">
        <div class="section-header">
            <span class="section-tag">Nossa Equipe</span>
            <h2 class="section-title">Profissionais Qualificados</h2>
            <p class="section-subtitle">Conheça quem vai cuidar de você</p>
        </div>
        
        <div class="staff-grid">
            <?php foreach ($staff as $member): ?>
            <div class="staff-card">
                <div class="staff-avatar">
                    <?php if (!empty($member['avatar'])): ?>
                        <img src="<?php echo htmlspecialchars($member['avatar']); ?>" alt="<?php echo htmlspecialchars($member['name']); ?>">
                    <?php else: ?>
                        <?php echo strtoupper(substr($member['name'], 0, 1)); ?>
                    <?php endif; ?>
                </div>
                <div class="staff-name"><?php echo htmlspecialchars($member['name']); ?></div>
                <div class="staff-role">
                    <?php 
                    $roles = ['owner' => 'Proprietário', 'barber' => 'Barbeiro', 'employee' => 'Profissional'];
                    echo $roles[$member['role']] ?? 'Profissional'; 
                    ?>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- CTA -->
<section class="cta" id="agendar">
    <div class="container">
        <h2>Pronto para agendar?</h2>
        <p>Reserve seu horário agora mesmo e garanta atendimento de qualidade.</p>
        <a href="/loja/<?php echo htmlspecialchars($store['slug'] ?? ''); ?>/agendar" class="btn">
            <iconify-icon icon="solar:calendar-bold"></iconify-icon>
            Agendar Horário
        </a>
    </div>
</section>

<!-- Footer -->
<footer class="footer">
    <div class="footer-grid">
        <div class="footer-brand">
            <a href="#" class="logo">
                <?php if (!empty($logo)): ?>
                    <img src="<?php echo htmlspecialchars($logo); ?>" alt="">
                <?php else: ?>
                    <iconify-icon icon="solar:scissors-bold"></iconify-icon>
                <?php endif; ?>
                <?php echo htmlspecialchars($storeName); ?>
            </a>
            <p><?php echo $storeType; ?> com atendimento de excelência. Agende seu horário online.</p>
        </div>
        
        <div>
            <h4 class="footer-title">Horários</h4>
            <ul class="footer-info">
                <?php foreach ($workingHours as $wh): ?>
                <li>
                    <iconify-icon icon="solar:clock-circle-bold"></iconify-icon>
                    <?php echo $wh['day']; ?>: <?php echo $wh['hours']; ?>
                </li>
                <?php endforeach; ?>
            </ul>
        </div>
        
        <div>
            <h4 class="footer-title">Contato</h4>
            <ul class="footer-info">
                <?php if ($whatsapp): ?>
                <li>
                    <iconify-icon icon="mdi:whatsapp"></iconify-icon>
                    <?php echo htmlspecialchars($whatsapp); ?>
                </li>
                <?php endif; ?>
                <?php if ($address || $city): ?>
                <li>
                    <iconify-icon icon="solar:map-point-bold"></iconify-icon>
                    <?php echo htmlspecialchars(trim($address . ($city ? ', ' . $city : ''))); ?>
                </li>
                <?php endif; ?>
            </ul>
        </div>
    </div>
    
    <div class="footer-bottom">
        <span>&copy; <?php echo date('Y'); ?> <?php echo htmlspecialchars($storeName); ?>. Todos os direitos reservados.</span>
        <div class="powered-by">
            Powered by <a href="https://barber.duolead.com.br" target="_blank">BarberFlow</a>
        </div>
    </div>
</footer>

<?php if ($whatsapp): ?>
<!-- WhatsApp Float -->
<a href="https://wa.me/55<?php echo preg_replace('/\D/', '', $whatsapp); ?>" target="_blank" class="whatsapp-float" title="Fale conosco no WhatsApp">
    <iconify-icon icon="mdi:whatsapp"></iconify-icon>
</a>
<?php endif; ?>

<script>
// Smooth scroll
document.querySelectorAll('a[href^="#"]').forEach(a => {
    a.addEventListener('click', function(e) {
        e.preventDefault();
        const target = document.querySelector(this.getAttribute('href'));
        if (target) {
            target.scrollIntoView({ behavior: 'smooth', block: 'start' });
        }
    });
});
</script>
</body>
</html>
