

import Container from '@/components/frontend/Container'
import OfferHeader from '@/components/frontend/offers/OfferHeader'
import CouponCard from '@/components/frontend/offers/CouponCard'
import { getCurrencySettings } from '@/lib/db/queries/getCurrencySettings'
import { formatCurrency } from '@/lib/utils/currency'
import type { CurrencyLike } from '@/lib/utils/currency'

function buildCoupons(currency: CurrencyLike) {
  const money = (amount: number) => formatCurrency(amount, currency)
  return [
  {
    id: 1,
    code: 'SAVE10',
    title: '10% Off on Everything',
    description: 'Get 10% discount on all products. No minimum order required.',
    discountType: 'percentage' as const,
    discountValue: 10,
    minOrder: 0,
    validUntil: 'May 31, 2026',
    usedCount: 245,
    totalLimit: 1000,
  },
  {
    id: 2,
    code: 'WELCOME100',
    title: 'New User Special',
    description: `${money(100)} off on your first order. Minimum order ${money(500)}.`,
    discountType: 'fixed' as const,
    discountValue: 100,
    minOrder: 500,
    validUntil: 'June 30, 2026',
    usedCount: 1234,
    totalLimit: 5000,
  },
  {
    id: 3,
    code: 'MEAT20',
    title: 'Meat Lover\'s Deal',
    description: `20% off on all meat products. Minimum order ${money(1500)}.`,
    discountType: 'percentage' as const,
    discountValue: 20,
    minOrder: 1500,
    validUntil: 'May 25, 2026',
    usedCount: 89,
    totalLimit: 500,
  },
  {
    id: 4,
    code: 'VEGGIE15',
    title: 'Fresh Vegetables',
    description: `15% off on all vegetables. Minimum order ${money(300)}.`,
    discountType: 'percentage' as const,
    discountValue: 15,
    minOrder: 300,
    validUntil: 'May 28, 2026',
    usedCount: 456,
    totalLimit: 2000,
  },
  {
    id: 5,
    code: 'FREEDEL',
    title: 'Free Delivery',
    description: `Free delivery on all orders above ${money(1000)}.`,
    discountType: 'fixed' as const,
    discountValue: 50,
    minOrder: 1000,
    validUntil: 'June 15, 2026',
    usedCount: 2345,
    totalLimit: 10000,
  },
  {
    id: 6,
    code: 'BIGSAVE50',
    title: 'Big Savings',
    description: `${money(50)} off on orders above ${money(1000)}.`,
    discountType: 'fixed' as const,
    discountValue: 50,
    minOrder: 1000,
    validUntil: 'May 20, 2026',
    usedCount: 678,
    totalLimit: 500,
  },
  ]
}

export const metadata = {
  title: 'Coupons - DesiCart.pk',
  description: 'Save money with DesiCart.pk coupons. Get discounts on your grocery shopping.',
}

export default async function CouponsPage() {
  const currency = await getCurrencySettings()
  const coupons = buildCoupons(currency)
  return (
    <>
      <OfferHeader
        title="Coupons & Promo Codes"
        subtitle="Save money on your orders"
        description="Copy and apply coupon codes at checkout to get instant discounts on your grocery shopping!"
        icon="ticket"
        badgeText="Save More"
      />
      
      <Container className="py-8">
        <div className="space-y-4">
          {coupons.map((coupon) => (
            <CouponCard key={coupon.id} {...coupon} />
          ))}
        </div>

        {/* Help Text */}
        <div className="mt-8 text-center">
          <p className="text-sm text-gray-custom">
            💡 How to use: Copy the coupon code and paste it at checkout to apply the discount.
          </p>
        </div>
      </Container>
    </>
  )
}