'use client';

import { useEffect, useState } from 'react';
import Link from 'next/link';
import Image from 'next/image';
import { agentsService, type AgentType } from '@/services/agents.service';

const footerLinks = {
  resources: {
    title: 'Resources',
    links: [
      { label: "Buyer's Guide", href: '/coming-soon' },
      { label: "Seller's Guide", href: '/coming-soon' },
      { label: 'FAQs', href: '/faq' },
      { label: 'Education', href: '/education' },
      { label: 'MyAgentNavigator', href: '/coming-soon' },
    ],
  },
  aboutContact: {
    title: 'About & Contact',
    links: [
      { label: 'About Us', href: '/about' },
      { label: 'Contact Us', href: '/contact' },
      { label: 'Privacy Policy', href: '/privacy-policy' },
      { label: 'Terms & Conditions', href: '/terms-of-service' },
    ],
  },
};

const socialLinks = [
  {
    name: 'LinkedIn',
    href: 'https://www.linkedin.com/company/re-quest001/posts/?feedView=all',
    icon: (
      <svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
        <path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.238-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z" />
      </svg>
    ),
    bgColor: 'bg-[#0077b5]',
  },
  {
    name: 'Instagram',
    href: 'https://www.instagram.com/re.quest.official',
    icon: (
      <svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
        <path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z" />
      </svg>
    ),
    bgColor: 'bg-gradient-to-br from-[#f09433] via-[#e6683c] to-[#bc1888]',
  },
  {
    name: 'Facebook',
    href: 'https://www.facebook.com/re.quest.social',
    icon: (
      <svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
        <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>
    ),
    bgColor: 'bg-[#1877f2]',
  },
  {
    name: 'X',
    href: 'https://x.com/RE_Quest_Social',
    icon: (
      <svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
        <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>
    ),
    bgColor: 'bg-black',
  },
];

export function Footer() {
  const [agentTypes, setAgentTypes] = useState<AgentType[]>([]);

  useEffect(() => {
    agentsService.getAgentTypes().then(setAgentTypes).catch(() => {});
  }, []);

  return (
    <footer className="bg-[#648188] text-[#00293d]">
      {/* Main Footer Content */}
      <div className="max-w-7xl mx-auto px-6 py-12">
        <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-8 lg:gap-12">
          {/* Service Providers */}
          <div>
            <h3 className="font-serif font-bold text-[14px] leading-[19px] text-[#E58625] mb-4 pb-2 border-b-2 border-[#e58625] inline-block">
              Service Providers
            </h3>
            <ul className="space-y-3">
              {agentTypes.map((type) => (
                <li key={type.id}>
                  <Link
                    href={`/user/profiles?type=${type.id}`}
                    prefetch={false}
                    className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
                  >
                    {type.name}
                  </Link>
                </li>
              ))}
            </ul>
          </div>

          {/* Resources */}
          <div>
            <h3 className="font-serif font-bold text-[14px] leading-[19px] text-[#E58625] mb-4 pb-2 border-b-2 border-[#e58625] inline-block">
              {footerLinks.resources.title}
            </h3>
            <ul className="space-y-3">
              {footerLinks.resources.links.map((link) => (
                <li key={link.label}>
                  <Link
                    href={link.href}
                    prefetch={false}
                    className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
                  >
                    {link.label}
                  </Link>
                </li>
              ))}
            </ul>
          </div>

          {/* About & Contact */}
          <div>
            <h3 className="font-serif font-bold text-[14px] leading-[19px] text-[#E58625] mb-4 pb-2 border-b-2 border-[#e58625] inline-block">
              {footerLinks.aboutContact.title}
            </h3>
            <ul className="space-y-3">
              {footerLinks.aboutContact.links.map((link) => (
                <li key={link.label}>
                  <Link
                    href={link.href}
                    prefetch={false}
                    className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D] hover:text-[#e58625] transition-colors"
                  >
                    {link.label}
                  </Link>
                </li>
              ))}
            </ul>
          </div>
        </div>
      </div>

      {/* Logo and Social Section */}
      <div className="border-t-2 border-[#F0F5FC]/20">
        <div className="max-w-7xl mx-auto px-6 py-6">
          <div className="flex flex-col md:flex-row items-center justify-between gap-6">
            {/* Logo and Tagline */}
            <div className="flex items-center gap-4">
              <Image
                src="/assets/logo.svg"
                alt="RE-Quest"
                width={150}
                height={40}
                className="h-10 w-auto"
              />
              <span className="font-serif font-normal text-[14px] leading-[19px] text-[#00293D]">
                Your Trusted Real Estate Partner
              </span>
            </div>

            {/* Social Links */}
            <div className="flex items-center gap-3">
              {socialLinks.map((social) => (
                <a
                  key={social.name}
                  href={social.href}
                  target="_blank"
                  rel="noopener noreferrer"
                  className={`w-7 h-7 ${social.bgColor} rounded flex items-center justify-center text-white hover:opacity-80 transition-opacity`}
                  aria-label={social.name}
                >
                  {social.icon}
                </a>
              ))}
            </div>
          </div>
        </div>
      </div>

      {/* Copyright Section */}
      <div className="border-t-2 border-[#F0F5FC]/20">
        <div className="max-w-7xl mx-auto px-6 py-4">
          <div className="flex flex-col md:flex-row items-center justify-between gap-4">
            <p className="font-serif font-normal text-[15px] leading-[21px] text-[#00293D]">Copyright © 2025 RE-Quest. All rights reserved.</p>
            <Link href="/privacy-policy" prefetch={false} className="font-serif font-normal text-[15px] leading-[21px] text-[#00293D] hover:text-[#e58625] transition-colors">
              Privacy Policy
            </Link>
          </div>
        </div>
      </div>
    </footer>
  );
}
