import React, { useEffect, useState } from 'react'; import { ArrowLeft, Clock, Calendar, Share2, ArrowRight, Mail, CheckCircle2, Copy, Check, Send, Tag } from 'lucide-react'; import { assetUrl } from '../lib/assetUrl'; const normalizeTags = (rawTags) => { if (!rawTags) return []; if (Array.isArray(rawTags)) return rawTags.map(t => String(t).trim()).filter(Boolean); if (typeof rawTags === 'string') { try { const parsed = JSON.parse(rawTags); if (Array.isArray(parsed)) return parsed.map(t => String(t).trim()).filter(Boolean); } catch {} return rawTags.split(',').map(t => t.trim()).filter(Boolean); } return []; }; export default function BlogDetailPage({ blog, allBlogs = [], isMobile, onNavigate, onSelectBlog }) { const [newsletterEmail, setNewsletterEmail] = useState(''); const [newsletterSubmitted, setNewsletterSubmitted] = useState(false); const [copied, setCopied] = useState(false); useEffect(() => { window.scrollTo({ top: 0, behavior: 'smooth' }); }, [blog?.id || blog?.slug]); useEffect(() => { if (!blog) return; const prevTitle = document.title; const pageTitle = blog.metaTitle || `${blog.title} | Cavin Infotech`; document.title = pageTitle; const metaDesc = blog.metaDescription || blog.excerpt || ''; const tagList = normalizeTags(blog.tags); const metaKeywords = blog.keywords || tagList.join(', '); const setMetaTag = (name, content, attr = 'name') => { if (!content) return; let el = document.querySelector(`meta[${attr}="${name}"]`); if (!el) { el = document.createElement('meta'); el.setAttribute(attr, name); document.head.appendChild(el); } el.setAttribute('content', content); }; setMetaTag('description', metaDesc); setMetaTag('keywords', metaKeywords); setMetaTag('og:title', pageTitle, 'property'); setMetaTag('og:description', metaDesc, 'property'); setMetaTag('og:type', 'article', 'property'); setMetaTag('og:url', window.location.href, 'property'); if (blog.ogImage || blog.coverImage || blog.image) { setMetaTag('og:image', assetUrl(blog.ogImage || blog.coverImage || blog.image), 'property'); } setMetaTag('twitter:card', 'summary_large_image'); setMetaTag('twitter:title', pageTitle); setMetaTag('twitter:description', metaDesc); let canonical = document.querySelector('link[rel="canonical"]'); if (!canonical) { canonical = document.createElement('link'); canonical.setAttribute('rel', 'canonical'); document.head.appendChild(canonical); } canonical.setAttribute('href', blog.canonicalURL || window.location.href); let scriptTag = document.getElementById('json-ld-article-schema'); if (!scriptTag) { scriptTag = document.createElement('script'); scriptTag.id = 'json-ld-article-schema'; scriptTag.type = 'application/ld+json'; document.head.appendChild(scriptTag); } const jsonLdData = { '@context': 'https://schema.org', '@type': 'BlogPosting', 'headline': blog.title, 'description': metaDesc, 'image': assetUrl(blog.ogImage || blog.coverImage || blog.image || '/assets/cavin_logo.svg'), 'datePublished': blog.publishDate || blog.date || new Date().toISOString(), 'author': { '@type': 'Person', 'name': blog.author || 'Cavin Infotech', 'jobTitle': blog.authorDesignation || '' }, 'publisher': { '@type': 'Organization', 'name': 'Cavin Infotech', 'logo': { '@type': 'ImageObject', 'url': window.location.origin + assetUrl('/assets/cavin_logo.svg') } }, 'mainEntityOfPage': { '@type': 'WebPage', '@id': blog.canonicalURL || window.location.href }, 'keywords': metaKeywords }; scriptTag.textContent = JSON.stringify(jsonLdData); return () => { document.title = prevTitle; if (scriptTag) scriptTag.remove(); }; }, [blog]); if (!blog) { return (

Article Not Found

The requested publication could not be loaded.

); } const bgPatternUrl = assetUrl('/assets/Background pattern About Us Hero section.svg'); const spotlightUrl = assetUrl('/assets/Spotlight vector.svg'); const authorName = (typeof blog.authorName === 'string' && blog.authorName.trim()) ? blog.authorName.trim() : (typeof blog.author === 'string' && blog.author.trim() ? blog.author.trim() : (blog.author?.firstname ? `${blog.author.firstname} ${blog.author.lastname || ''}`.trim() : 'Cavin Editorial Team')); const authorRole = typeof blog.authorDesignation === 'string' ? blog.authorDesignation : 'Chief AI Architect & Head of Data Engineering'; const authorAvatar = '/assets/arvindh_agentic_ai.jpg'; const relatedArticles = allBlogs.filter(b => b.id !== blog.id).slice(0, 2); const handleNewsletterSubmit = (e) => { e.preventDefault(); if (newsletterEmail) { setNewsletterSubmitted(true); setTimeout(() => { setNewsletterSubmitted(false); setNewsletterEmail(''); }, 5000); } }; const handleCopyLink = () => { navigator.clipboard.writeText(window.location.href); setCopied(true); setTimeout(() => setCopied(false), 2500); }; const handleSocialShare = (platform) => { const url = encodeURIComponent(window.location.href); const text = encodeURIComponent(blog.title); let shareUrl = ''; if (platform === 'twitter') { shareUrl = `https://twitter.com/intent/tweet?url=${url}&text=${text}`; } else if (platform === 'facebook') { shareUrl = `https://www.facebook.com/sharer/sharer.php?u=${url}`; } else if (platform === 'linkedin') { shareUrl = `https://www.linkedin.com/sharing/share-offsite/?url=${url}`; } if (shareUrl) window.open(shareUrl, '_blank', 'noopener,noreferrer'); }; return (
{/* Background Pattern SVG Overlay - Fixed Hero Height Only */}
{/* Spotlight Vector SVG at Top-Left Corner - Fixed Hero Height Only */}
{/* Main Content Container */}
{/* Top Breadcrumbs & Back Button */}
onNavigate('Home')}>Home / onNavigate('Blogs')}>Blogs / {blog.title}
{/* HERO DESIGN SECTION */}
{/* Combined Category & Read Time Pill Badge */}
{blog.category || 'Leadership'} {blog.readTime || '8 min read'}
{/* Title */}

{blog.title}

{/* Subtitle / Excerpt */} {(blog.subtitle || blog.excerpt) && (

{blog.subtitle || blog.excerpt}

)}
{/* HERO FEATURED IMAGE */} {(blog.image || blog.coverImage || blog.ogImage) && (
{blog.title} { const titleLower = (blog.title || '').toLowerCase(); const catLower = (blog.category || '').toLowerCase(); let fallback = '/assets/arvindh_agentic_ai.jpg'; if (titleLower.includes('llm')) fallback = '/assets/arvindh_llm_financial.jpg'; else if (titleLower.includes('supply chain')) fallback = '/assets/arvindh_supply_chain.jpg'; else if (titleLower.includes('prodmax')) fallback = '/assets/prodmax_dashboard.png'; else if (titleLower.includes('vr') || titleLower.includes('incidents')) fallback = '/assets/whyus_vr_man.jpg'; else if (titleLower.includes('scada') || titleLower.includes('plc') || titleLower.includes('speed vs')) fallback = '/assets/arvindh_agentic_ai.jpg'; else if (catLower.includes('ai')) fallback = '/assets/arvindh_agentic_ai.jpg'; const resolvedFallback = assetUrl(fallback); if (e.currentTarget.src !== resolvedFallback) { e.currentTarget.src = resolvedFallback; } }} />
)} {/* METADATA & ACTION BAR UNDER FEATURED IMAGE */}
{/* Written by & Published on */}
Written by
{authorName}
Published on
{blog.date || '11 Jul 2026'}
{/* Social Share & Action Icons */}
{/* X / Twitter */} {/* Facebook */} {/* LinkedIn */}
{/* TWO COLUMN ARTICLE CONTENT LAYOUT */}
{/* MAIN ARTICLE COLUMN */}
{/* Lead Excerpt Quote Block */} {blog.excerpt && (
"{blog.excerpt}"
)} {/* Article Content Body */}
{(blog.content || blog.excerpt || '') .replace(/(!\[.*?\]\(.*?\))/g, '\n\n$1\n\n') .split(/\n\s*\n/) .map(b => b.trim()) .filter(Boolean) .map((block, idx) => { if (block.startsWith('# ')) { return (

{block.replace('# ', '')}

); } if (block.startsWith('## ')) { return (

{block.replace('## ', '')}

); } if (block.startsWith('### ')) { return (

{block.replace('### ', '')}

); } if (block.startsWith('#### ')) { return (

{block.replace('#### ', '')}

); } if (block.startsWith('> ')) { return (
{block.replace('> ', '')}
); } if (block.startsWith('- ') || block.startsWith('* ')) { const items = block.split('\n'); return (
    {items.map((item, itemIdx) => { const itemText = item.replace(/^[-*]\s+/, ''); return (
  • {itemText}
  • ); })}
); } if (/^\d+\.\s/.test(block)) { const items = block.split('\n'); return (
    {items.map((item, itemIdx) => { const itemText = item.replace(/^\d+\.\s+/, ''); return (
  1. {itemText}
  2. ); })}
); } const mdImgMatch = block.match(/!\[(.*?)\]\((.*?)\)/); const htmlImgMatch = block.match(/]+src=["']([^"']+)["'][^>]*>/i); if (mdImgMatch || htmlImgMatch) { const caption = mdImgMatch ? (mdImgMatch[1] ? mdImgMatch[1].trim() : '') : ''; const rawImgUrl = mdImgMatch ? mdImgMatch[2] : htmlImgMatch[1]; const resolvedSrc = assetUrl(rawImgUrl); const isFilename = caption && /\.(jpg|jpeg|png|gif|webp|svg|bmp)$/i.test(caption); const displayCaption = caption && !isFilename ? caption : null; return (
{displayCaption { if (rawImgUrl && rawImgUrl.includes('/uploads/')) { const uploadPath = rawImgUrl.substring(rawImgUrl.indexOf('/uploads/')); const fallback = assetUrl(uploadPath); if (e.currentTarget.src !== fallback) { e.currentTarget.src = fallback; } } }} /> {displayCaption && (
{displayCaption}
)}
); } return

{block}

; })}
{/* TAG BADGES SECTION */} {normalizeTags(blog.tags).length > 0 && (
Tags:
{normalizeTags(blog.tags).map((tag, tagIdx) => ( { e.currentTarget.style.background = 'rgba(56, 189, 248, 0.18)'; e.currentTarget.style.borderColor = 'rgba(56, 189, 248, 0.5)'; }} onMouseLeave={e => { e.currentTarget.style.background = 'rgba(56, 189, 248, 0.08)'; e.currentTarget.style.borderColor = 'rgba(56, 189, 248, 0.25)'; }} > #{tag} ))}
)} {/* AUTHOR SECTION - MATCHING MOCKUP DESIGN EXACTLY */}
{/* Italic Author Bio Paragraph */}

{blog.authorBio || `${authorName} is ${authorRole} at CAVIN INFOTECH FZE, a Dubai-based technology company delivering AR/VR experiences, AI solutions, and digital transformation for real estate and enterprises across the UAE and beyond. Connect with us to explore a smarter way to sell.`}

{/* Author Profile Row */}
{authorName}
{authorName}
{authorRole}
{/* RIGHT SIDEBAR */}
{/* Weekly Newsletter Subscription Card */}
{/* Paperplane Icon Container */}
{/* Title */}

Weekly newsletter

{/* Description */}

No spam. Just the latest releases and tips, interesting articles, and exclusive interviews in your inbox every week.

{!newsletterSubmitted ? (
{/* Email Input */} setNewsletterEmail(e.target.value)} style={{ width: '100%', background: 'rgba(255, 255, 255, 0.03)', border: '1px solid rgba(255, 255, 255, 0.12)', borderRadius: '10px', padding: '0.8rem 1rem', color: '#ffffff', fontSize: '0.92rem', outline: 'none', boxSizing: 'border-box', transition: 'border-color 0.2s ease' }} onFocus={e => e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.3)'} onBlur={e => e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.12)'} /> {/* Privacy Policy text */} {/* Subscribe Button */}
) : (
✓ Thanks for subscribing! Check your inbox for confirmation.
)}
{/* BOTTOM "FROM THE BLOG" SECTION - MATCHING MOCKUP DESIGN */} {relatedArticles.length > 0 && (
{/* Left Column Header & CTA */}
Latest

From the blog

The latest industry news, interviews, technologies, and resources.

{/* Chevron Navigation Indicator */}
{/* Right Column Blog Cards */}
{relatedArticles.map((rel, i) => (
{ if (onSelectBlog) onSelectBlog(rel); }} style={{ height: '440px', borderRadius: '18px', overflow: 'hidden', position: 'relative', cursor: 'pointer', border: '1px solid rgba(255, 255, 255, 0.12)', boxShadow: '0 12px 35px rgba(0, 0, 0, 0.5)', transition: 'all 0.35s cubic-bezier(0.4, 0, 0.2, 1)' }} onMouseEnter={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.3)'; e.currentTarget.style.transform = 'translateY(-6px)'; e.currentTarget.style.boxShadow = '0 18px 45px rgba(0, 0, 0, 0.7)'; }} onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.12)'; e.currentTarget.style.transform = 'translateY(0)'; e.currentTarget.style.boxShadow = '0 12px 35px rgba(0, 0, 0, 0.5)'; }} > {/* Full-bleed card image */} {rel.title} {/* Dark bottom panel */}
{(rel.category || 'ARTICLE').toUpperCase()}

{rel.title}

Read Blog
))}
)}
); }