<?php

function getLandingPageData($user_id, $conn) {
    // Ambil slug URL
    $sql = "SELECT slug_url FROM landingpage WHERE id_user = ?";
    $stmt = $conn->prepare($sql);
    if (!$stmt) return null;
    
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();
    $stmt->close();

    $disabled = ($row == null);
    $slug_url = $row['slug_url'] ?? "#";

    // Ambil jumlah data dari beberapa tabel
    $sql = "
        SELECT 
            (SELECT COUNT(*) FROM datausaha WHERE id_user = ?) AS datausaha_count,
            (SELECT COUNT(*) FROM seo WHERE id_user = ?) AS seo_count,
            (SELECT COUNT(*) FROM testimoni WHERE id_user = ?) AS testimoni_count,
            (SELECT COUNT(*) FROM produk WHERE id_user = ?) AS produk_count,
            (SELECT COUNT(*) FROM keunggulan WHERE id_user = ?) AS keunggulan_count
    ";
    
    $stmt = $conn->prepare($sql);
    if (!$stmt) return null;
    
    $stmt->bind_param("iiiii", $user_id, $user_id, $user_id, $user_id, $user_id);
    $stmt->execute();
    $result = $stmt->get_result();
    $row = $result->fetch_assoc();
    $stmt->close();

    $showLandingPage = (
        $row['datausaha_count'] > 0 &&
        $row['seo_count'] > 0 &&
        $row['testimoni_count'] > 0 &&
        $row['produk_count'] > 0 &&
        $row['keunggulan_count'] > 0
    );

    return [
        'disabled' => $disabled,
        'slug_url' => $slug_url,
        'showLandingPage' => $showLandingPage
    ];
}
?>

