// Social links configuration - reads from environment variables
// All links are optional - if not set, they won't be displayed
export interface SocialLinks {
whatsapp?: string;
instagram?: string;
email?: string;
telegram?: string;
}
export interface SocialLink {
type: 'whatsapp' | 'instagram' | 'email' | 'telegram';
url: string;
label: string;
handle?: string;
}
// Get raw values from env
export const socialConfig: SocialLinks = {
whatsapp: process.env.NEXT_PUBLIC_WHATSAPP || undefined,
instagram: process.env.NEXT_PUBLIC_INSTAGRAM || undefined,
email: process.env.NEXT_PUBLIC_EMAIL || undefined,
telegram: process.env.NEXT_PUBLIC_TELEGRAM || undefined,
};
// Generate URLs from handles/values
export function getWhatsAppUrl(value?: string): string | null {
if (!value) return null;
// If it's already a full URL (group invite link or wa.me link), return as-is
if (value.startsWith('https://') || value.startsWith('http://')) {
return value;
}
// Otherwise, treat as phone number - remove any non-digit characters except +
const clean = value.replace(/[^\d+]/g, '');
return `https://wa.me/${clean.replace('+', '')}`;
}
export function getInstagramUrl(value?: string): string | null {
if (!value) return null;
// If it's already a full URL, return as-is
if (value.startsWith('https://') || value.startsWith('http://')) {
return value;
}
// Otherwise, treat as handle - remove @ if present
const clean = value.replace('@', '');
return `https://instagram.com/${clean}`;
}
export function getEmailUrl(email?: string): string | null {
if (!email) return null;
return `mailto:${email}`;
}
export function getTelegramUrl(value?: string): string | null {
if (!value) return null;
// If it's already a full URL, return as-is
if (value.startsWith('https://') || value.startsWith('http://')) {
return value;
}
// Otherwise, treat as handle - remove @ if present
const clean = value.replace('@', '');
return `https://t.me/${clean}`;
}
// Extract display handle from URL or value
function extractInstagramHandle(value: string): string {
// If it's a URL, extract the username from the path
if (value.startsWith('http')) {
const match = value.match(/instagram\.com\/([^/?]+)/);
return match ? `@${match[1]}` : '@instagram';
}
// Otherwise it's already a handle
return `@${value.replace('@', '')}`;
}
function extractTelegramHandle(value: string): string {
// If it's a URL, extract the channel/username from the path
if (value.startsWith('http')) {
const match = value.match(/t\.me\/([^/?]+)/);
return match ? `@${match[1]}` : '@telegram';
}
// Otherwise it's already a handle
return `@${value.replace('@', '')}`;
}
// Get all active social links as an array
export function getSocialLinks(): SocialLink[] {
const links: SocialLink[] = [];
if (socialConfig.whatsapp) {
const url = getWhatsAppUrl(socialConfig.whatsapp);
if (url) {
links.push({
type: 'whatsapp',
url,
label: 'WhatsApp',
handle: '@WhatsApp community',
});
}
}
if (socialConfig.instagram) {
const url = getInstagramUrl(socialConfig.instagram);
if (url) {
links.push({
type: 'instagram',
url,
label: 'Instagram',
handle: extractInstagramHandle(socialConfig.instagram),
});
}
}
if (socialConfig.email) {
const url = getEmailUrl(socialConfig.email);
if (url) {
links.push({
type: 'email',
url,
label: 'Email',
handle: socialConfig.email,
});
}
}
if (socialConfig.telegram) {
const url = getTelegramUrl(socialConfig.telegram);
if (url) {
links.push({
type: 'telegram',
url,
label: 'Telegram',
handle: extractTelegramHandle(socialConfig.telegram),
});
}
}
return links;
}
// SVG icons for each platform
export const socialIcons = {
whatsapp: (
),
instagram: (
),
email: (
),
telegram: (
),
};