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.
onNavigate('Blogs')}
style={{
background: 'linear-gradient(135deg, #ffaa00 0%, #ff8800 100%)',
color: '#000000',
border: 'none',
padding: '0.8rem 2rem',
borderRadius: '50px',
fontWeight: 700,
cursor: 'pointer',
boxShadow: '0 4px 20px rgba(255, 170, 0, 0.3)'
}}
>
Return to Blogs
);
}
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}
onNavigate('Blogs')}
style={{
display: 'flex',
alignItems: 'center',
gap: '0.45rem',
background: 'rgba(255, 255, 255, 0.05)',
border: '1px solid rgba(255, 255, 255, 0.12)',
color: '#ffffff',
padding: '0.45rem 1.1rem',
borderRadius: '50px',
fontSize: '0.82rem',
fontWeight: 600,
cursor: 'pointer',
transition: 'all 0.2s ease'
}}
onMouseEnter={e => { e.currentTarget.style.borderColor = '#38bdf8'; e.currentTarget.style.color = '#38bdf8'; }}
onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.12)'; e.currentTarget.style.color = '#ffffff'; }}
>
Back to Blogs
{/* 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) && (
{
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 */}
Published on
{blog.date || '11 Jul 2026'}
{/* Social Share & Action Icons */}
{ e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.3)'; e.currentTarget.style.background = 'rgba(255, 255, 255, 0.08)'; }}
onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.15)'; e.currentTarget.style.background = 'rgba(255, 255, 255, 0.05)'; }}
>
{copied ? : }
{copied ? 'Copied!' : 'Copy link'}
{/* X / Twitter */}
handleSocialShare('twitter')}
title="Share on X"
style={{
width: '36px',
height: '36px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'rgba(255, 255, 255, 0.05)',
border: '1px solid rgba(255, 255, 255, 0.15)',
borderRadius: '8px',
color: '#ffffff',
fontSize: '0.85rem',
fontWeight: 700,
cursor: 'pointer',
transition: 'all 0.2s ease'
}}
onMouseEnter={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.3)'; e.currentTarget.style.background = 'rgba(255, 255, 255, 0.08)'; }}
onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.15)'; e.currentTarget.style.background = 'rgba(255, 255, 255, 0.05)'; }}
>
𝕏
{/* Facebook */}
handleSocialShare('facebook')}
title="Share on Facebook"
style={{
width: '36px',
height: '36px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'rgba(255, 255, 255, 0.05)',
border: '1px solid rgba(255, 255, 255, 0.15)',
borderRadius: '8px',
color: '#ffffff',
cursor: 'pointer',
transition: 'all 0.2s ease'
}}
onMouseEnter={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.3)'; e.currentTarget.style.background = 'rgba(255, 255, 255, 0.08)'; }}
onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.15)'; e.currentTarget.style.background = 'rgba(255, 255, 255, 0.05)'; }}
>
{/* LinkedIn */}
handleSocialShare('linkedin')}
title="Share on LinkedIn"
style={{
width: '36px',
height: '36px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'rgba(255, 255, 255, 0.05)',
border: '1px solid rgba(255, 255, 255, 0.15)',
borderRadius: '8px',
color: '#ffffff',
cursor: 'pointer',
transition: 'all 0.2s ease'
}}
onMouseEnter={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.3)'; e.currentTarget.style.background = 'rgba(255, 255, 255, 0.08)'; }}
onMouseLeave={e => { e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.15)'; e.currentTarget.style.background = 'rgba(255, 255, 255, 0.05)'; }}
>
{/* 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 (
{itemText}
);
})}
);
}
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 (
{
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}
{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 ? (
) : (
✓ 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.
onNavigate('Home')}
style={{
background: '#091b33',
border: '1px solid rgba(255, 255, 255, 0.15)',
color: '#ffffff',
padding: '0.75rem 1.6rem',
borderRadius: '50px',
fontSize: '0.9rem',
fontWeight: 700,
cursor: 'pointer',
transition: 'all 0.25s ease',
marginBottom: '2.5rem',
boxShadow: '0 4px 15px rgba(0, 0, 0, 0.4)'
}}
onMouseEnter={e => {
e.currentTarget.style.background = '#0e2646';
e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.3)';
}}
onMouseLeave={e => {
e.currentTarget.style.background = '#091b33';
e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.15)';
}}
>
View All Posts
{/* 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 */}
{/* Dark bottom panel */}
{(rel.category || 'ARTICLE').toUpperCase()}
{rel.title}
))}
)}
);
}