<?php
/**
 * Google Reviews Component
 * Displays Google Business Profile reviews with rating badge
 */

$googleRating = 4.6;
$reviewCount = 9;
$googleReviewsUrl = 'https://www.google.com/search?q=Mark%27s+Tech+Solution+Weymouth+reviews';

$reviews = [
    [
        'author' => 'Depot Computers',
        'rating' => 5,
        'date' => '2 days ago',
        'text' => "We use Mark for all of our Boston IT needs to support our office there. Great service, well worth his rate, I think he should charge more and I know everyone would still pay. If you have any doubts about using him or not, you will not be disappointed if you choose to call him. Highly Recommended and I can't say enough to express our gratitude for finding him.",
        'avatar' => 'D'
    ],
    [
        'author' => 'Jill Collmer',
        'rating' => 5,
        'date' => '9 weeks ago',
        'text' => "Mark was incredibly responsive and helpful. He arrived on time, worked diligently through the troubleshooting process, and showed a genuine commitment to resolving the issue. It's clear he truly cares about his clients. A pleasure to work with.",
        'avatar' => 'J'
    ],
    [
        'author' => 'Dan Yotive',
        'rating' => 5,
        'date' => '36 weeks ago',
        'text' => 'My laptop keyboard had not been working for several months and Mark both diagnosed and solved my issue same day, and most importantly was able to avoid a costly parts replacement. Very grateful!',
        'avatar' => 'D'
    ],
    [
        'author' => 'Kyle White',
        'rating' => 5,
        'date' => '41 weeks ago',
        'text' => "I have used Mark on many occasions regarding various issues. Mark has always been extremely helpful, courteous and professional. I would highly recommend Mark to any person or business that needs expert assistance especially immediately. Thank You Mark, you are wonderful!",
        'avatar' => 'K'
    ],
    [
        'author' => 'Ignatius Njuguna',
        'rating' => 5,
        'date' => 'Jun 27, 2025',
        'text' => "I visited Mark Tech Solution with a Laptop issue. It would not start. Mark devoted his energy & skills to help and revive my Laptop. His patience and serious commitment to the issue at hand seemed very impressive. His honesty in telling you what is needed was equally admirable. I think he's the right technician if you have any IT issues that you cannot solve.",
        'avatar' => 'I'
    ],
    [
        'author' => 'Siobhan Carroll',
        'rating' => 5,
        'date' => 'May 26, 2025',
        'text' => 'Fantastic service! Quick and efficient. Would recommend to all family & friends!',
        'avatar' => 'S'
    ],
    [
        'author' => 'Gary Morris',
        'rating' => 5,
        'date' => 'Sep 13, 2024',
        'text' => "Mark's Tech Solution has come to the rescue on many occasions and has saved the day. Hope Bible Church is a network of house churches that meets via zoom. Without Mark's technical expertise and patience we would never have made this work. He has been an unbelievable plus. Everyone he has helped in the church has commented on how nice he is to work with and how patient he is. All of my interactions with Mark have been wonderful. I cannot say enough about him and his company.",
        'avatar' => 'G'
    ],
    [
        'author' => 'Marian McCarthy',
        'rating' => 5,
        'date' => 'Dec 30, 2022',
        'text' => 'Mark was very helpful with my Mac problem. Very honest. It was a pleasure doing business with him. I highly recommend his services.',
        'avatar' => 'M'
    ],
    [
        'author' => 'Robyn Cohen',
        'rating' => 5,
        'date' => 'Jul 12, 2022',
        'text' => "Doesn't get better than this!",
        'avatar' => 'R'
    ]
];

function renderStars($rating) {
    $output = '';
    for ($i = 1; $i <= 5; $i++) {
        if ($i <= floor($rating)) {
            $output .= '<i class="fas fa-star"></i>';
        } elseif ($i == ceil($rating) && $rating - floor($rating) >= 0.5) {
            $output .= '<i class="fas fa-star-half-alt"></i>';
        } else {
            $output .= '<i class="far fa-star"></i>';
        }
    }
    return $output;
}
?>

<section id="testimonials" class="reviews-section">
    <div class="container">
        <div class="reviews-header text-center">
            <h2 class="reviews-title">What Our Customers Say</h2>
            <p class="reviews-subtitle">Trusted by homeowners and businesses throughout East Weymouth and the South Shore</p>
            
            <div class="google-rating-badge">
                <div class="rating-score"><?php echo $googleRating; ?></div>
                <div class="rating-details">
                    <div class="rating-stars"><?php echo renderStars($googleRating); ?></div>
                    <div class="rating-count">Google rating · <?php echo $reviewCount; ?> reviews</div>
                </div>
                <a href="<?php echo htmlspecialchars($googleReviewsUrl); ?>" target="_blank" rel="noopener noreferrer" class="review-us-link">
                    <i class="fab fa-google"></i> Read our reviews
                </a>
            </div>
        </div>
        
        <div class="reviews-grid">
            <?php foreach ($reviews as $review): ?>
                <div class="review-card">
                    <div class="review-card-header">
                        <div class="review-avatar"><?php echo htmlspecialchars($review['avatar']); ?></div>
                        <div class="review-meta">
                            <div class="review-author"><?php echo htmlspecialchars($review['author']); ?></div>
                            <div class="review-date"><?php echo htmlspecialchars($review['date']); ?></div>
                        </div>
                    </div>
                    <div class="review-stars"><?php echo renderStars($review['rating']); ?></div>
                    <p class="review-text"><?php echo htmlspecialchars($review['text']); ?></p>
                </div>
            <?php endforeach; ?>
        </div>
        
        <div class="text-center mt-5">
            <a href="<?php echo htmlspecialchars($googleReviewsUrl); ?>" target="_blank" rel="noopener noreferrer" class="btn btn-outline-primary btn-lg">
                <i class="fab fa-google me-2"></i>Read all <?php echo $reviewCount; ?> reviews on Google
            </a>
        </div>
    </div>
</section>

<style>
.reviews-section {
    padding: 5rem 0;
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
}

.reviews-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: #1a1a1a;
}

.reviews-subtitle {
    font-size: 1.15rem;
    color: #666;
    margin-bottom: 2rem;
}

.google-rating-badge {
    display: inline-flex;
    align-items: center;
    gap: 1rem;
    background: #ffffff;
    border: 2px solid #ff6600;
    border-radius: 16px;
    padding: 1rem 1.5rem;
    margin-bottom: 3rem;
    box-shadow: 0 4px 20px rgba(255, 102, 0, 0.15);
}

.rating-score {
    font-size: 2.5rem;
    font-weight: 800;
    color: #ff6600;
    line-height: 1;
}

.rating-details {
    text-align: left;
}

.rating-stars {
    color: #ffb400;
    font-size: 1rem;
    letter-spacing: 2px;
}

.rating-count {
    font-size: 0.9rem;
    color: #555;
    margin-top: 0.2rem;
}

.review-us-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: #ff6600;
    color: #ffffff;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.2s ease;
}

.review-us-link:hover {
    background: #e55a00;
    color: #ffffff;
}

.reviews-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.review-card {
    background: #ffffff;
    border-radius: 16px;
    padding: 1.75rem;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.review-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
}

.review-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.review-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6600 0%, #ff8c00 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
}

.review-meta {
    text-align: left;
}

.review-author {
    font-weight: 700;
    color: #1a1a1a;
    font-size: 1rem;
}

.review-date {
    font-size: 0.85rem;
    color: #888;
}

.review-stars {
    color: #ffb400;
    font-size: 0.9rem;
    letter-spacing: 2px;
    margin-bottom: 0.75rem;
}

.review-text {
    color: #444;
    line-height: 1.6;
    margin: 0;
    font-size: 0.95rem;
}

.btn-outline-primary {
    border-color: #ff6600;
    color: #ff6600;
    font-weight: 600;
}

.btn-outline-primary:hover {
    background: #ff6600;
    border-color: #ff6600;
    color: #ffffff;
}

@media (max-width: 768px) {
    .reviews-title {
        font-size: 2rem;
    }
    
    .google-rating-badge {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }
    
    .rating-details {
        text-align: center;
    }
    
    .reviews-grid {
        grid-template-columns: 1fr;
    }
}
</style>
