'use client';

import React, { useState, useEffect } from 'react';
import { Sparkles, Loader2, Volume2, BookOpen, Lightbulb, Share2, X, VolumeX } from 'lucide-react';
import Image from 'next/image';

interface ArticleContentProps {
  content: string;
  summary: string;
  title: string;
}

// İçerik içindeki resimleri çıkar (HTML ve Markdown formatlarından)
function extractContentImages(text: string): string[] {
  const images: string[] = [];

  // HTML img taglerinden
  const imgRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/gi;
  let match;
  while ((match = imgRegex.exec(text)) !== null) {
    images.push(match[1]);
  }

  // Markdown formatından ![alt](url)
  const mdImgRegex = /!\[([^\]]*)\]\(([^)]+)\)/g;
  while ((match = mdImgRegex.exec(text)) !== null) {
    images.push(match[2]);
  }

  return images;
}

// Markdown ve içeriği zengin HTML'e çevir
function parseMarkdown(text: string, summary: string): { html: string; images: string[]; videos: string[] } {
  // İçerik resimlerini ve videolarını çıkar
  const images = extractContentImages(text);
  const videos: string[] = [];

  // Video URL'lerini bul
  const videoRegex = /https?:\/\/[^\s)]+\.(mp4|webm|ogg)/gi;
  let videoMatch;
  while ((videoMatch = videoRegex.exec(text)) !== null) {
    videos.push(videoMatch[0]);
  }

  // YouTube embed URL'lerini bul
  const youtubeRegex = /https?:\/\/(?:www\.)?(?:youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)([a-zA-Z0-9_-]+)/gi;
  while ((videoMatch = youtubeRegex.exec(text)) !== null) {
    videos.push(`https://www.youtube.com/embed/${videoMatch[1]}`);
  }

  // HTML taglerini temizle ama resim URL'lerini kaydet
  let cleanText = text
    .replace(/<img[^>]*>/gi, '') // HTML resim taglerini kaldır
    .replace(/<video[^>]*>[\s\S]*?<\/video>/gi, '') // Video taglerini kaldır
    .replace(/<iframe[^>]*>[\s\S]*?<\/iframe>/gi, '') // iframe kaldır
    .replace(/<[^>]*>/g, '') // Diğer HTML taglerini temizle
    .replace(/&nbsp;/g, ' ')
    .replace(/&amp;/g, '&')
    .replace(/&lt;/g, '<')
    .replace(/&gt;/g, '>')
    .replace(/&quot;/g, '"')
    .replace(/&#39;/g, "'");

  // Summary ile başlayan tekrarlanan içeriği kaldır
  const summaryFirst50 = summary.substring(0, 50).toLowerCase().trim();
  const lines = cleanText.split(/\n/);
  const processedLines: string[] = [];
  let skipFirstParagraph = false;

  // İlk paragraf summary ile aynı mı kontrol et
  for (let i = 0; i < lines.length; i++) {
    const line = lines[i].trim();
    if (!line) continue;

    // İlk non-empty satırı kontrol et
    if (!skipFirstParagraph && line.toLowerCase().substring(0, 50).includes(summaryFirst50.substring(0, 30))) {
      skipFirstParagraph = true;
      continue; // Bu satırı atla (tekrar)
    }
    break;
  }

  for (let i = 0; i < lines.length; i++) {
    let line = lines[i].trim();
    if (!line) {
      processedLines.push('');
      continue;
    }

    // İlk paragrafı atla (tekrarlama önleme)
    if (skipFirstParagraph && i === 0) {
      skipFirstParagraph = false;
      continue;
    }

    // Markdown resim ![alt](url) - resmi render et
    if (/^!\[([^\]]*)\]\(([^)]+)\)$/.test(line)) {
      const imgMatch = line.match(/^!\[([^\]]*)\]\(([^)]+)\)$/);
      if (imgMatch) {
        const alt = imgMatch[1] || 'Haber görseli';
        const url = imgMatch[2];
        processedLines.push(`<figure class="my-8"><img src="${url}" alt="${alt}" class="w-full rounded-xl shadow-lg" loading="lazy" /><figcaption class="text-center text-sm text-gray-500 mt-2">${alt}</figcaption></figure>`);
        continue;
      }
    }

    // Satır içi markdown resim (metin içinde)
    if (/!\[([^\]]*)\]\(([^)]+)\)/.test(line)) {
      line = line.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_, alt, url) => {
        return `</p><figure class="my-8"><img src="${url}" alt="${alt || 'Görsel'}" class="w-full rounded-xl shadow-lg" loading="lazy" /><figcaption class="text-center text-sm text-gray-500 mt-2">${alt || ''}</figcaption></figure><p class="mb-6 text-[17px] leading-8 text-gray-700">`;
      });
    }

    // Markdown ## başlık
    if (line.startsWith('## ')) {
      const heading = line.substring(3).trim();
      processedLines.push(`<h2 class="text-2xl font-bold text-gray-900 mt-10 mb-5 pb-3 border-b-2 border-red-100">${heading}</h2>`);
      continue;
    }

    // Markdown ### başlık
    if (line.startsWith('### ')) {
      const heading = line.substring(4).trim();
      processedLines.push(`<h3 class="text-xl font-semibold text-gray-800 mt-8 mb-4 flex items-center gap-2"><span class="w-1 h-6 bg-red-500 rounded-full"></span>${heading}</h3>`);
      continue;
    }

    // BÜYÜK HARFLE YAZILMIŞ BAŞLIKLARI tespit et (en az 3 kelime, hepsi büyük)
    const words = line.split(/\s+/);
    const allUpperCase = words.length >= 2 && words.every(word => {
      // Türkçe karakterler dahil büyük harf kontrolü
      return /^[A-ZÇĞİÖŞÜ0-9\-'":,\.!?]+$/i.test(word) && word === word.toUpperCase();
    });

    if (allUpperCase && line.length > 8 && line.length < 80 && !/[a-zçğıöşü]/.test(line)) {
      processedLines.push(`<h2 class="text-2xl font-bold text-gray-900 mt-10 mb-5 pb-3 border-b-2 border-red-100">${line}</h2>`);
      continue;
    }

    // Blockquote
    if (line.startsWith('> ')) {
      processedLines.push(`<blockquote class="border-l-4 border-red-500 pl-5 py-3 my-6 bg-red-50 rounded-r-xl italic text-gray-700">${line.substring(2)}</blockquote>`);
      continue;
    }

    // Liste - item
    if (line.startsWith('- ') || line.startsWith('• ')) {
      const content = line.substring(2).trim();
      processedLines.push(`<li class="flex items-start gap-3 mb-3 text-[17px] leading-8 text-gray-700"><span class="w-2 h-2 bg-red-500 rounded-full mt-3 flex-shrink-0"></span><span>${content}</span></li>`);
      continue;
    }

    // Numaralı liste
    if (/^\d+[\.\)]\s/.test(line)) {
      const content = line.replace(/^\d+[\.\)]\s/, '').trim();
      processedLines.push(`<li class="mb-3 text-[17px] leading-8 text-gray-700 list-decimal ml-6">${content}</li>`);
      continue;
    }

    // Bold **text** ve *text*
    line = line.replace(/\*\*([^*]+)\*\*/g, '<strong class="font-semibold text-gray-900">$1</strong>');
    line = line.replace(/\*([^*]+)\*/g, '<em>$1</em>');

    // Normal paragraf
    if (line.length > 5) {
      processedLines.push(`<p class="mb-6 text-[17px] leading-8 text-gray-700">${line}</p>`);
    }
  }

  // HTML birleştir
  let html = processedLines.filter(l => l).join('\n');

  // Ardışık boş paragrafları temizle
  html = html.replace(/<p[^>]*>\s*<\/p>/g, '');

  // Ardışık <li> taglarını <ul> içine al
  html = html.replace(/(<li class="flex[^"]*"[^>]*>[\s\S]*?<\/li>\s*)+/g, (match) => `<ul class="my-6 space-y-1">${match}</ul>`);

  
  
  return { html, images, videos };
}

export default function ArticleContent({ content, summary, title }: ArticleContentProps) {
  const [showAiSummary, setShowAiSummary] = useState(false);
  const [aiSummary, setAiSummary] = useState<string | null>(null);
  const [isLoading, setIsLoading] = useState(false);
  const [isReading, setIsReading] = useState(false);
  const [showShareModal, setShowShareModal] = useState(false);
  const [isMobile, setIsMobile] = useState(false);

  // Mobil cihaz kontrolü
  useEffect(() => {
    const checkMobile = () => setIsMobile(window.innerWidth < 768);
    checkMobile();
    window.addEventListener('resize', checkMobile);
    return () => window.removeEventListener('resize', checkMobile);
  }, []);

  // Sesli okuma durduğunda state güncelle
  useEffect(() => {
    return () => {
      window.speechSynthesis.cancel();
    };
  }, []);

  const generateAiSummary = async () => {
    if (aiSummary) {
      setShowAiSummary(!showAiSummary);
      return;
    }

    setIsLoading(true);
    setShowAiSummary(true);

    try {
      const response = await fetch('/api/assistant', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          query: `Bu haberi 3-4 madde halinde özetle. Her madde kısa ve öz olsun:\n\nBaşlık: ${title}\n\nİçerik: ${content.substring(0, 2000)}`
        }),
      });

      const data = await response.json();
      setAiSummary(data.response || 'Özet oluşturulamadı.');
    } catch {
      setAiSummary('Özet oluşturulurken bir hata oluştu.');
    } finally {
      setIsLoading(false);
    }
  };

  const readAloud = () => {
    if (isReading) {
      window.speechSynthesis.cancel();
      setIsReading(false);
      return;
    }

    const textToRead = content.replace(/[#*\->\n]/g, ' ').replace(/\s+/g, ' ');
    const utterance = new SpeechSynthesisUtterance(textToRead);
    utterance.lang = 'tr-TR';
    utterance.rate = 0.9;
    utterance.onend = () => setIsReading(false);
    utterance.onerror = () => setIsReading(false);
    window.speechSynthesis.speak(utterance);
    setIsReading(true);
  };

  const openShareModal = () => {
    setShowShareModal(true);
  };

  const shareToSocial = (platform: string) => {
    const url = encodeURIComponent(window.location.href);
    const text = encodeURIComponent(title);

    let shareUrl = '';
    switch (platform) {
      case 'whatsapp':
        shareUrl = `https://wa.me/?text=${text}%20${url}`;
        break;
      case 'twitter':
        shareUrl = `https://twitter.com/intent/tweet?text=${text}&url=${url}`;
        break;
      case 'facebook':
        shareUrl = `https://www.facebook.com/sharer/sharer.php?u=${url}`;
        break;
      case 'telegram':
        shareUrl = `https://t.me/share/url?url=${url}&text=${text}`;
        break;
      case 'linkedin':
        shareUrl = `https://www.linkedin.com/sharing/share-offsite/?url=${url}`;
        break;
      case 'copy':
        navigator.clipboard.writeText(window.location.href);
        setShowShareModal(false);
        return;
    }

    window.open(shareUrl, '_blank', 'width=600,height=400');
    setShowShareModal(false);
  };

  const { html: parsedContent, images: contentImages, videos: contentVideos } = parseMarkdown(content, summary);
  const readTime = Math.ceil(content.split(/\s+/).length / 200);

  return (
    <div className="article-content-wrapper">
      {/* Lead Paragraph - Özet */}
      <p className="text-xl font-medium text-gray-900 leading-relaxed mb-8 first-letter:text-5xl first-letter:font-bold first-letter:text-red-600 first-letter:float-left first-letter:mr-3 first-letter:mt-1">
        {summary}
      </p>

      {/* İçerik Videoları (varsa) */}
      {contentVideos.length > 0 && (
        <div className="my-8">
          {contentVideos.slice(0, 2).map((videoUrl, idx) => (
            <div key={idx} className="relative w-full aspect-video rounded-xl overflow-hidden bg-gray-900 mb-4">
              {videoUrl.includes('youtube.com') ? (
                <iframe
                  src={videoUrl}
                  className="w-full h-full"
                  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
                  allowFullScreen
                  title={`${title} - Video ${idx + 1}`}
                />
              ) : (
                <video
                  src={videoUrl}
                  controls
                  className="w-full h-full object-contain"
                  preload="metadata"
                >
                  Tarayıcınız video oynatmayı desteklemiyor.
                </video>
              )}
            </div>
          ))}
        </div>
      )}

      {/* İçerik Resimleri (varsa) */}
      {contentImages.length > 0 && (
        <div className="my-8 space-y-4">
          {contentImages.slice(0, 3).map((imgUrl, idx) => (
            <figure key={idx} className="relative">
              <div className="relative w-full aspect-video rounded-xl overflow-hidden bg-gray-100">
                {/* eslint-disable-next-line @next/next/no-img-element */}
                <img
                  src={imgUrl}
                  alt={`${title} - Görsel ${idx + 1}`}
                  className="w-full h-full object-cover"
                  loading="lazy"
                  onError={(e) => {
                    (e.target as HTMLImageElement).style.display = 'none';
                  }}
                />
              </div>
              <figcaption className="text-center text-sm text-gray-500 mt-2">
                {title} - Görsel {idx + 1}
              </figcaption>
            </figure>
          ))}
        </div>
      )}

      {/* Main Content */}
      <div
        className="article-body prose prose-lg max-w-none"
        dangerouslySetInnerHTML={{ __html: parsedContent }}
      />

      {/* Okuma Bilgisi */}
      <div className="flex items-center gap-2 mt-8 pt-6 border-t border-gray-100 text-sm text-gray-500">
        <BookOpen size={16} />
        <span>{readTime} dakika okuma süresi</span>
      </div>

      {/* Read More Indicator */}
      <div className="mt-8 p-6 bg-gradient-to-r from-gray-50 to-slate-50 rounded-2xl border border-gray-100">
        <div className="flex items-start gap-4">
          <div className="p-3 bg-red-100 rounded-xl">
            <Sparkles size={24} className="text-red-600" />
          </div>
          <div>
            <h4 className="font-bold text-gray-900 mb-1">Bu haberi beğendiniz mi?</h4>
            <p className="text-gray-600 text-sm">
              Van ve çevresinden güncel haberleri takip etmek için sitemizi ziyaret etmeye devam edin.
            </p>
          </div>
        </div>
      </div>

      {/* ========== MOBİL ALT BAR - HABER SAYFASI İÇİN ========== */}
      <div className="md:hidden fixed bottom-0 left-0 right-0 z-50">
        {/* Blur Background */}
        <div className="absolute inset-0 bg-white/90 backdrop-blur-xl border-t border-gray-200/50 shadow-2xl" />
        
        <div className="relative flex items-center justify-around h-[70px] pb-safe">
          {/* Ana Sayfa */}
          <a
            href="/"
            className="flex flex-col items-center justify-center flex-1 h-full pt-2"
          >
            <div className="p-2 rounded-2xl hover:bg-gray-100 transition-all duration-300 active:scale-95">
              <svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="text-gray-500">
                <path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
                <polyline points="9 22 9 12 15 12 15 22"/>
              </svg>
            </div>
            <span className="text-[10px] font-semibold mt-1 text-gray-500">Ana Sayfa</span>
          </a>

          {/* AI Özetle */}
          <button
            onClick={generateAiSummary}
            className="flex flex-col items-center justify-center flex-1 h-full pt-2"
          >
            <div className={`p-2 rounded-2xl transition-all duration-300 active:scale-95 ${
              showAiSummary ? 'bg-purple-100' : 'hover:bg-gray-100'
            }`}>
              <Sparkles size={22} className={`${showAiSummary ? 'text-purple-600' : 'text-gray-500'} ${isLoading ? 'animate-pulse' : ''}`} />
            </div>
            <span className={`text-[10px] font-semibold mt-1 ${showAiSummary ? 'text-purple-600' : 'text-gray-500'}`}>
              AI Özet
            </span>
          </button>

          {/* Sesli Oku */}
          <button
            onClick={readAloud}
            className="flex flex-col items-center justify-center flex-1 h-full pt-2"
          >
            <div className={`p-2 rounded-2xl transition-all duration-300 active:scale-95 ${
              isReading ? 'bg-green-100' : 'hover:bg-gray-100'
            }`}>
              {isReading ? (
                <VolumeX size={22} className="text-green-600" />
              ) : (
                <Volume2 size={22} className="text-gray-500" />
              )}
            </div>
            <span className={`text-[10px] font-semibold mt-1 ${isReading ? 'text-green-600' : 'text-gray-500'}`}>
              {isReading ? 'Durdur' : 'Dinle'}
            </span>
          </button>

          {/* Paylaş */}
          <button
            onClick={openShareModal}
            className="flex flex-col items-center justify-center flex-1 h-full pt-2"
          >
            <div className="p-2 rounded-2xl hover:bg-gray-100 transition-all duration-300 active:scale-95">
              <Share2 size={22} className="text-gray-500" />
            </div>
            <span className="text-[10px] font-semibold mt-1 text-gray-500">Paylaş</span>
          </button>
        </div>
      </div>

      {/* Alt bar için boşluk */}
      <div className="md:hidden h-[70px]" />

      {/* ========== MOBİL AI ÖZET PANELİ ========== */}
      {isMobile && showAiSummary && (
        <div className="fixed inset-x-0 bottom-0 z-[60] animate-slideUp">
          <div className="bg-white rounded-t-3xl shadow-2xl max-h-[70vh] overflow-hidden">
            {/* Handle */}
            <div className="flex justify-center pt-3 pb-2">
              <div className="w-10 h-1 bg-gray-300 rounded-full" />
            </div>

            {/* Header */}
            <div className="flex items-center justify-between px-5 pb-3 border-b border-gray-100">
              <div className="flex items-center gap-3">
                <div className="p-2 bg-gradient-to-r from-purple-600 to-blue-600 rounded-xl">
                  <Lightbulb size={18} className="text-white" />
                </div>
                <h3 className="font-bold text-gray-900">AI Haber Özeti</h3>
              </div>
              <button
                onClick={() => setShowAiSummary(false)}
                className="p-2 hover:bg-gray-100 rounded-full transition-colors"
              >
                <X size={20} className="text-gray-500" />
              </button>
            </div>

            {/* Content */}
            <div className="p-5 pb-28 overflow-y-auto max-h-[50vh]">
              {isLoading ? (
                <div className="flex flex-col items-center gap-3 py-12">
                  <Loader2 size={32} className="animate-spin text-purple-600" />
                  <span className="text-gray-600 animate-pulse">Yapay zeka analiz ediyor...</span>
                </div>
              ) : (
                <div className="text-gray-700 leading-relaxed whitespace-pre-line">
                  {aiSummary}
                </div>
              )}
            </div>
          </div>

          {/* Backdrop */}
          <div
            className="fixed inset-0 bg-black/30 -z-10"
            onClick={() => setShowAiSummary(false)}
          />
        </div>
      )}

      {/* ========== PAYLAŞ MODAL ========== */}
      {showShareModal && (
        <div className="fixed inset-0 z-[70] flex items-end md:items-center justify-center">
          {/* Backdrop */}
          <div
            className="absolute inset-0 bg-black/50 backdrop-blur-sm"
            onClick={() => setShowShareModal(false)}
          />

          {/* Modal */}
          <div className="relative bg-white rounded-t-3xl md:rounded-2xl w-full md:max-w-sm shadow-2xl animate-slideUp md:animate-fade-in">
            {/* Handle (mobile only) */}
            <div className="flex justify-center pt-3 pb-2 md:hidden">
              <div className="w-10 h-1 bg-gray-300 rounded-full" />
            </div>

            {/* Header */}
            <div className="flex items-center justify-between px-5 py-4 border-b border-gray-100">
              <h3 className="font-bold text-gray-900 text-lg">Haberi Paylaş</h3>
              <button
                onClick={() => setShowShareModal(false)}
                className="p-2 hover:bg-gray-100 rounded-full transition-colors"
              >
                <X size={20} className="text-gray-500" />
              </button>
            </div>

            {/* Share Buttons */}
            <div className="p-5 grid grid-cols-4 gap-4">
              {/* WhatsApp */}
              <button
                onClick={() => shareToSocial('whatsapp')}
                className="flex flex-col items-center gap-2"
              >
                <div className="w-14 h-14 rounded-full bg-[#25D366] flex items-center justify-center">
                  <svg viewBox="0 0 24 24" className="w-7 h-7 text-white fill-current">
                    <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/>
                  </svg>
                </div>
                <span className="text-xs text-gray-600">WhatsApp</span>
              </button>

              {/* Twitter */}
              <button
                onClick={() => shareToSocial('twitter')}
                className="flex flex-col items-center gap-2"
              >
                <div className="w-14 h-14 rounded-full bg-black flex items-center justify-center">
                  <svg viewBox="0 0 24 24" className="w-6 h-6 text-white fill-current">
                    <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/>
                  </svg>
                </div>
                <span className="text-xs text-gray-600">X</span>
              </button>

              {/* Facebook */}
              <button
                onClick={() => shareToSocial('facebook')}
                className="flex flex-col items-center gap-2"
              >
                <div className="w-14 h-14 rounded-full bg-[#1877F2] flex items-center justify-center">
                  <svg viewBox="0 0 24 24" className="w-7 h-7 text-white fill-current">
                    <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/>
                  </svg>
                </div>
                <span className="text-xs text-gray-600">Facebook</span>
              </button>

              {/* Telegram */}
              <button
                onClick={() => shareToSocial('telegram')}
                className="flex flex-col items-center gap-2"
              >
                <div className="w-14 h-14 rounded-full bg-[#0088cc] flex items-center justify-center">
                  <svg viewBox="0 0 24 24" className="w-6 h-6 text-white fill-current">
                    <path d="M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"/>
                  </svg>
                </div>
                <span className="text-xs text-gray-600">Telegram</span>
              </button>

              {/* LinkedIn */}
              <button
                onClick={() => shareToSocial('linkedin')}
                className="flex flex-col items-center gap-2"
              >
                <div className="w-14 h-14 rounded-full bg-[#0A66C2] flex items-center justify-center">
                  <svg viewBox="0 0 24 24" className="w-6 h-6 text-white fill-current">
                    <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
                  </svg>
                </div>
                <span className="text-xs text-gray-600">LinkedIn</span>
              </button>

              {/* Copy Link */}
              <button
                onClick={() => shareToSocial('copy')}
                className="flex flex-col items-center gap-2"
              >
                <div className="w-14 h-14 rounded-full bg-gray-500 flex items-center justify-center">
                  <svg viewBox="0 0 24 24" className="w-6 h-6 text-white fill-none stroke-current" strokeWidth="2">
                    <path strokeLinecap="round" strokeLinejoin="round" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1" />
                  </svg>
                </div>
                <span className="text-xs text-gray-600">Kopyala</span>
              </button>
            </div>

            {/* Safe area for mobile */}
            <div className="h-6 md:hidden" />
          </div>
        </div>
      )}
    </div>
  );
}




