'use client';

import Link from 'next/link';
import { useLanguage } from '@/context/LanguageContext';
import Card from '@/components/ui/Card';
import Button from '@/components/ui/Button';
import { 
  ChatBubbleLeftRightIcon, 
  CameraIcon,
  UserGroupIcon,
  HeartIcon 
} from '@heroicons/react/24/outline';
import { 
  socialConfig, 
  getWhatsAppUrl, 
  getInstagramUrl, 
  getTelegramUrl,
  getTikTokUrl 
} from '@/lib/socialLinks';

export default function CommunityPage() {
  const { t } = useLanguage();
  
  // Get social URLs from environment config
  const whatsappUrl = getWhatsAppUrl(socialConfig.whatsapp);
  const instagramUrl = getInstagramUrl(socialConfig.instagram);
  const telegramUrl = getTelegramUrl(socialConfig.telegram);
  const tiktokUrl = getTikTokUrl(socialConfig.tiktok);

  const guidelines = t('community.guidelines.items') as unknown as string[];

  return (
    <div className="section-padding">
      <div className="container-page">
        <div className="text-center max-w-2xl mx-auto">
          <h1 className="section-title">{t('community.title')}</h1>
          <p className="section-subtitle">{t('community.subtitle')}</p>
        </div>

        {/* Social Links */}
        <div className="mt-16 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8 max-w-6xl mx-auto">
          {/* WhatsApp Card */}
          {whatsappUrl && (
            <Card className="p-8 text-center card-hover h-full flex flex-col">
              <div className="w-20 h-20 mx-auto bg-green-100 rounded-full flex items-center justify-center">
                <svg className="w-10 h-10 text-green-600" fill="currentColor" viewBox="0 0 24 24">
                  <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>
              <h3 className="mt-6 text-xl font-semibold">{t('community.whatsapp.title')}</h3>
              <p className="mt-3 text-gray-600 flex-grow">{t('community.whatsapp.description')}</p>
              <a 
                href={whatsappUrl}
                target="_blank" 
                rel="noopener noreferrer"
                className="inline-block mt-6"
              >
                <Button>
                  {t('community.whatsapp.button')}
                </Button>
              </a>
            </Card>
          )}

          {/* Telegram Card */}
          {telegramUrl && (
            <Card className="p-8 text-center card-hover h-full flex flex-col">
              <div className="w-20 h-20 mx-auto bg-blue-100 rounded-full flex items-center justify-center">
                <svg className="w-10 h-10 text-blue-500" fill="currentColor" viewBox="0 0 24 24">
                  <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>
              <h3 className="mt-6 text-xl font-semibold">{t('community.telegram.title')}</h3>
              <p className="mt-3 text-gray-600 flex-grow">{t('community.telegram.description')}</p>
              <a 
                href={telegramUrl}
                target="_blank" 
                rel="noopener noreferrer"
                className="inline-block mt-6"
              >
                <Button>
                  {t('community.telegram.button')}
                </Button>
              </a>
            </Card>
          )}

          {/* Instagram Card */}
          {instagramUrl && (
            <Card className="p-8 text-center card-hover h-full flex flex-col">
              <div className="w-20 h-20 mx-auto bg-gradient-to-br from-purple-500 to-pink-500 rounded-full flex items-center justify-center">
                <CameraIcon className="w-10 h-10 text-white" />
              </div>
              <h3 className="mt-6 text-xl font-semibold">{t('community.instagram.title')}</h3>
              <p className="mt-3 text-gray-600 flex-grow">{t('community.instagram.description')}</p>
              <a 
                href={instagramUrl}
                target="_blank" 
                rel="noopener noreferrer"
                className="inline-block mt-6"
              >
                <Button>
                  {t('community.instagram.button')}
                </Button>
              </a>
            </Card>
          )}

          {/* TikTok Card */}
          {tiktokUrl && (
            <Card className="p-8 text-center card-hover h-full flex flex-col">
              <div className="w-20 h-20 mx-auto bg-black rounded-full flex items-center justify-center">
                <svg className="w-10 h-10 text-white" fill="currentColor" viewBox="0 0 24 24">
                  <path d="M19.59 6.69a4.83 4.83 0 0 1-3.77-4.25V2h-3.45v13.67a2.89 2.89 0 0 1-5.2 1.74 2.89 2.89 0 0 1 2.31-4.64 2.93 2.93 0 0 1 .88.13V9.4a6.84 6.84 0 0 0-1-.05A6.33 6.33 0 0 0 5 20.1a6.34 6.34 0 0 0 10.86-4.43v-7a8.16 8.16 0 0 0 4.77 1.52v-3.4a4.85 4.85 0 0 1-1-.1z"/>
                </svg>
              </div>
              <h3 className="mt-6 text-xl font-semibold">{t('community.tiktok.title')}</h3>
              <p className="mt-3 text-gray-600 flex-grow">{t('community.tiktok.description')}</p>
              <a 
                href={tiktokUrl}
                target="_blank" 
                rel="noopener noreferrer"
                className="inline-block mt-6"
              >
                <Button>
                  {t('community.tiktok.button')}
                </Button>
              </a>
            </Card>
          )}
        </div>

        {/* Guidelines */}
        <div className="mt-20 max-w-3xl mx-auto">
          <Card className="p-8">
            <div className="flex items-center gap-4 mb-6">
              <div className="w-12 h-12 bg-primary-yellow/20 rounded-full flex items-center justify-center">
                <HeartIcon className="w-6 h-6 text-primary-dark" />
              </div>
              <h2 className="text-2xl font-bold">{t('community.guidelines.title')}</h2>
            </div>
            
            <ul className="space-y-4">
              {Array.isArray(guidelines) && guidelines.map((item, index) => (
                <li key={index} className="flex items-start gap-3">
                  <span className="w-6 h-6 bg-primary-yellow rounded-full flex items-center justify-center text-sm font-semibold flex-shrink-0">
                    {index + 1}
                  </span>
                  <span className="text-gray-700">{item}</span>
                </li>
              ))}
            </ul>
          </Card>
        </div>

        {/* Volunteer Section */}
        <div className="mt-20 max-w-3xl mx-auto">
          <Card className="p-8 bg-gradient-to-br from-primary-yellow/10 to-secondary-blue/10">
            <div className="flex flex-col md:flex-row items-center gap-8">
              <div className="w-24 h-24 bg-white rounded-full flex items-center justify-center shadow-card flex-shrink-0">
                <UserGroupIcon className="w-12 h-12 text-primary-dark" />
              </div>
              <div className="text-center md:text-left">
                <h2 className="text-2xl font-bold">{t('community.volunteer.title')}</h2>
                <p className="mt-2 text-gray-600">{t('community.volunteer.description')}</p>
                <Link href="/contact" className="inline-block mt-4">
                  <Button variant="outline">
                    {t('community.volunteer.button')}
                  </Button>
                </Link>
              </div>
            </div>
          </Card>
        </div>
      </div>
    </div>
  );
}
