'use client';

import React from 'react';
import Link from 'next/link';
import Image from 'next/image';
import { TrendingUp, CloudSun, Send, MapPin, Flame } from 'lucide-react';
import { Article } from '@/types';

interface SidebarProps {
  popularNews?: Article[];
  showWeather?: boolean;
  showNewsletter?: boolean;
  showDistricts?: boolean;
}

export default function Sidebar({ 
  popularNews = [], 
  showWeather = true,
  showNewsletter = true,
  showDistricts = true 
}: SidebarProps) {
  return (
    <aside className="space-y-6">
      {/* Weather Widget */}
      {showWeather && (
        <div className="bg-gradient-to-br from-sky-400 via-blue-500 to-indigo-600 rounded-2xl p-5 text-white shadow-xl relative overflow-hidden">
          <div className="absolute top-0 right-0 w-32 h-32 bg-yellow-300/20 rounded-full blur-2xl" />
          <div className="relative z-10">
            <div className="flex items-center justify-between mb-3">
              <div className="flex items-center gap-2">
                <CloudSun size={20} />
                <span className="font-bold text-xs uppercase tracking-wider">Van</span>
              </div>
              <span className="text-xs opacity-80">Bugün</span>
            </div>
            <div className="flex items-end justify-between">
              <div>
                <span className="text-5xl font-black">18°</span>
                <p className="text-sm font-medium mt-1 opacity-90">Güneşli</p>
              </div>
              <div className="text-right text-[10px] space-y-1 opacity-80">
                <p>💧 %22</p>
                <p>💨 14 km/sa</p>
              </div>
            </div>
          </div>
        </div>
      )}

      {/* Popular News */}
      {popularNews.length > 0 && (
        <div className="bg-white rounded-2xl border border-gray-100 p-5">
          <div className="flex items-center gap-2 mb-4">
            <div className="w-8 h-8 bg-red-100 rounded-lg flex items-center justify-center">
              <Flame size={18} className="text-red-600" />
            </div>
            <h2 className="font-black text-sm uppercase tracking-tight">Çok Okunanlar</h2>
          </div>
          <div className="space-y-4">
            {popularNews.slice(0, 5).map((news, idx) => (
              <Link
                key={news.id}
                href={`/haber/${news.slug}`}
                className="flex gap-3 group"
              >
                <span className={`text-2xl font-black leading-none ${idx === 0 ? 'text-red-500' : idx === 1 ? 'text-orange-400' : idx === 2 ? 'text-yellow-500' : 'text-gray-200'}`}>
                  {idx + 1}
                </span>
                <div className="flex-1 min-w-0">
                  <h3 className="text-sm font-semibold text-gray-800 group-hover:text-red-600 transition-colors line-clamp-2 leading-tight">
                    {news.title}
                  </h3>
                  <span className="text-[10px] text-gray-400 mt-1 block">{news.category}</span>
                </div>
              </Link>
            ))}
          </div>
        </div>
      )}

      {/* Van İlçeleri */}
      {showDistricts && (
        <div className="bg-white rounded-2xl border border-gray-100 p-5">
          <div className="flex items-center gap-2 mb-4">
            <div className="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center">
              <MapPin size={18} className="text-blue-600" />
            </div>
            <h3 className="font-black text-sm uppercase tracking-tight">Van İlçeleri</h3>
          </div>
          <div className="grid grid-cols-3 gap-2">
            {['İpekyolu', 'Tuşba', 'Edremit', 'Erciş', 'Gevaş', 'Çaldıran'].map((ilce) => (
              <Link
                key={ilce}
                href={`/ilce/${ilce.toLowerCase().replace('ı', 'i').replace('ş', 's').replace('ü', 'u').replace('ç', 'c')}`}
                className="text-center p-2.5 bg-gray-50 rounded-xl text-xs font-medium text-gray-600 hover:bg-red-50 hover:text-red-600 transition-all hover:scale-105"
              >
                {ilce}
              </Link>
            ))}
          </div>
          <Link href="/ilceler" className="block text-center mt-3 text-xs font-bold text-red-600 hover:underline">
            Tüm İlçeler →
          </Link>
        </div>
      )}

      {/* Newsletter */}
      {showNewsletter && (
        <div className="bg-gradient-to-br from-gray-900 to-gray-800 rounded-2xl p-5 text-white relative overflow-hidden">
          <div className="absolute -right-4 -top-4 w-24 h-24 bg-red-500/20 rounded-full blur-2xl" />
          <div className="relative z-10">
            <div className="flex items-center gap-2 mb-3">
              <div className="w-8 h-8 bg-white/10 rounded-lg flex items-center justify-center">
                <Send size={16} className="text-white" />
              </div>
              <h3 className="font-black text-sm">Haber Bülteni</h3>
            </div>
            <p className="text-xs text-gray-400 mb-4">
              Günün önemli haberleri e-postanıza gelsin.
            </p>
            <form className="space-y-2">
              <input
                type="email"
                placeholder="E-posta adresiniz"
                className="w-full px-4 py-3 bg-white/10 border border-white/10 rounded-xl text-sm text-white placeholder:text-gray-500 focus:outline-none focus:ring-2 focus:ring-red-500"
              />
              <button
                type="submit"
                className="w-full py-3 bg-red-600 text-white font-bold rounded-xl text-sm hover:bg-red-700 transition-colors"
              >
                Abone Ol
              </button>
            </form>
          </div>
        </div>
      )}
    </aside>
  );
}
