"use client"

import type React from "react"

import { useState } from "react"

export default function SiteFooter() {
  const [email, setEmail] = useState("")

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault()
    
    if (!email.trim()) {
      alert('Please enter a valid email address')
      return
    }

    try {
      const response = await fetch('/api/mailchimp/subscribe', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({ email }),
      })

      const result = await response.json()

      if (result.success) {
        alert('Thank you for subscribing! Check your email for confirmation.')
        setEmail('')
      } else {
        alert(result.error || 'Subscription failed. Please try again.')
      }
    } catch (error) {
      console.error('Subscription error:', error)
      alert('Something went wrong. Please try again later.')
    }
  }

  return (
    <footer
      className="relative py-16 px-4"
      style={{
        backgroundImage: `url('/images/denim-footer-background.png')`,
        backgroundSize: "cover",
        backgroundPosition: "center",
        backgroundColor: "#a8b5c4",
      }}
    >
      <div className="container mx-auto relative z-10">
        <div className="grid grid-cols-1 md:grid-cols-3 gap-12 items-start">
          {/* Stay in Touch - Left Column */}
          <div className="space-y-6">
            <h2 className="text-4xl font-bold text-black font-serif">Get in Touch </h2>
            <form onSubmit={handleSubmit} className="space-y-4">
              <input
                type="email"
                placeholder="Email"
                value={email}
                onChange={(e) => setEmail(e.target.value)}
                className="w-full px-4 py-3 rounded bg-white text-gray-800 placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-yellow-400"
                required
              />
              <button
                type="submit"
                className="w-full bg-yellow-400 text-black py-3 px-6 font-semibold hover:bg-yellow-300 transition-colors"
              >
                SUBMIT
              </button>
            </form>
          </div>

          {/* Location & Contact - Center Column */}
          <div className="space-y-8">
            <div>
              <h3 className="text-lg font-bold text-white mb-2 tracking-wider">Our Location</h3>
              <p className="text-gray-700 font-medium">Revelstoke, BC</p>
            </div>

            <div>
              <h3 className="text-lg font-bold text-white mb-2 tracking-wider">Contact </h3>
              <p className="text-gray-700 font-medium">Aunty.Sparkles@gmail.com</p>
            </div>

            {/* Instagram Link */}
            <div>
              <h3 className="text-lg font-bold text-white mb-2 tracking-wider">Follow the Latest Designs </h3>
              <a
                href="https://www.instagram.com/aunty.sparkles/"
                target="_blank"
                rel="noopener noreferrer"
                className="inline-flex items-center space-x-2 text-gray-700 hover:text-black transition-colors"
              >
                <svg className="w-6 h-6" 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-.073-1.689-.073-4.948 0-3.204.013-3.583.072-4.948.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.40z" />
                </svg>
                <span className="font-medium">@aunty.sparkles</span>
              </a>
            </div>
          </div>

          {/* Hours - Right Column */}
          <div>
            <h3 className="text-lg font-bold text-white mb-4 tracking-wider">Hours</h3>
            <div className="space-y-2 text-gray-700 font-medium">
              <div className="flex gap-4">
                <span>M - F:</span>
                <span>8am-5pm</span>
              </div>
              <div className="flex gap-4">
                <span>Sat:</span>
                <span>11am-6pm</span>
              </div>
              <div className="flex gap-4">
                <span>Sun:</span>
                <span>Closed</span>
              </div>
            </div>
          </div>
        </div>

        {/* Bottom section */}
      </div>
    </footer>
  )
}
