import type { Metadata } from 'next'
import InternalPageTemplate from '@/components/InternalPageTemplate'
import BreadcrumbJsonLd from '@/components/BreadcrumbJsonLd'
import Link from 'next/link'
import { getTranslations } from 'next-intl/server'
import { buildAlternates } from '@/lib/seo'

export async function generateMetadata({
  params,
}: {
  params: Promise<{ locale: string }>
}): Promise<Metadata> {
  const { locale } = await params
  const t = await getTranslations('seo')
  const { canonical, languages } = buildAlternates(locale, '/guides/best-time-to-book-hotels')
  return {
    title: t('guideBestTime'),
    description:
      'Is it cheaper to book hotels early or last minute? The honest answer is: neither — unless you also check which country to search from. Here\'s what the data actually shows.',
    openGraph: {
      title: 'Best Time to Book a Hotel: When Prices Are Actually Lowest',
      description:
        'Early booking, last-minute deals, or mid-week searches — which actually saves money on hotels? The timing matters less than most people think.',
      type: 'article',
    },
    alternates: { canonical, languages },
  }
}

const articleSchema = {
  '@context': 'https://schema.org',
  '@type': 'Article',
  headline: 'Best Time to Book a Hotel: When Prices Are Actually Lowest',
  description:
    'Is it cheaper to book hotels early or last minute? The honest answer is: neither — unless you also check which country to search from. Here\'s what the data actually shows.',
  author: { '@type': 'Organization', name: 'CahooTravel' },
  publisher: {
    '@type': 'Organization',
    name: 'CahooTravel',
    logo: { '@type': 'ImageObject', url: 'https://www.cahootravel.com/cahootravel-logo.svg' },
  },
  datePublished: '2025-01-15',
  dateModified: '2025-01-15',
  mainEntityOfPage: 'https://www.cahootravel.com/guides/best-time-to-book-hotels',
}

export default function BestTimeToBookGuide() {
  return (
    <InternalPageTemplate>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(articleSchema) }}
      />

      <article className="max-w-3xl">
        {/* Header */}
        <div className="mb-10">
          <div className="flex items-center gap-3 mb-4">
            <span className="text-xs font-medium text-brand-purple bg-brand-purple-light px-2.5 py-1 rounded-full">
              Strategy
            </span>
            <span className="text-xs text-gray-400">7 min read</span>
          </div>
          <h1 className="text-4xl font-bold text-gray-900 mb-4 leading-tight">
            Best Time to Book a Hotel: When Prices Are Actually Lowest
          </h1>
          <p className="text-gray-500 text-lg leading-relaxed">
            "Book early to get the best price." "Wait for last-minute deals." You've heard both, and
            they contradict each other. The truth is more useful than either: hotel prices are set
            dynamically and timing is only one variable — and often not the most important one.
          </p>
        </div>

        {/* Featured image */}
        <div className="mb-10 rounded-2xl overflow-hidden aspect-[16/7]">
          <img
            src="/guides/best-time-to-book.jpg"
            alt="Airplane at dusk representing travel planning and booking timing"
            className="w-full h-full object-cover"
          />
        </div>

        <div className="prose prose-gray max-w-none text-sm leading-relaxed space-y-8">

          <section>
            <h2 className="text-2xl font-bold text-gray-900 mb-3">
              How hotel pricing actually works
            </h2>
            <p className="text-gray-600">
              Hotels don't set a single fixed price and hold it until check-in. They use
              <strong> dynamic pricing algorithms</strong> — the same technology airlines have used
              for decades — that adjust rates in real time based on demand, occupancy levels,
              competitor prices, time to arrival, and a growing number of other signals.
            </p>
            <p className="text-gray-600 mt-3">
              This means the price for a room tonight can be completely different from the price for
              the same room on the same night as seen three months ago, three weeks ago, or three
              hours ago. The algorithm is constantly optimising to fill rooms at the highest price the
              market will bear at that moment.
            </p>
            <p className="text-gray-600 mt-3">
              What this means for you: there is no universally "best" time to book. But there are
              patterns — and knowing them lets you make smarter decisions.
            </p>
          </section>

          <section>
            <h2 className="text-2xl font-bold text-gray-900 mb-3">
              Does booking early actually save money?
            </h2>
            <p className="text-gray-600">
              For popular destinations during peak season, yes — booking early often does lock in
              lower prices. Rooms are genuinely scarce during events, public holidays, and high
              season, so demand drives prices up as the date approaches. For a hotel in Tokyo during
              cherry blossom season or a property in Barcelona in August, booking 2–3 months out
              typically beats waiting.
            </p>
            <p className="text-gray-600 mt-3">
              For off-peak travel and less popular destinations, early booking advantage is much
              weaker. Hotels in these cases often lower prices as check-in approaches to fill
              remaining inventory, which is where "last-minute deal" logic comes from.
            </p>

            <div className="mt-6 overflow-x-auto">
              <table className="w-full text-xs border-collapse">
                <thead>
                  <tr className="bg-gray-50">
                    <th className="text-left px-4 py-3 font-semibold text-gray-700 border border-gray-200">Scenario</th>
                    <th className="text-left px-4 py-3 font-semibold text-gray-700 border border-gray-200">Book early?</th>
                    <th className="text-left px-4 py-3 font-semibold text-gray-700 border border-gray-200">Wait last-minute?</th>
                  </tr>
                </thead>
                <tbody>
                  {[
                    ['Peak season, popular city', 'Yes — often 15–30% cheaper', 'Risk: sold out or much higher'],
                    ['Major event / festival', 'Yes — book as early as possible', 'Very high risk, often 2–3× price'],
                    ['Off-peak, flexible destination', 'Neutral', 'Sometimes 10–20% cheaper'],
                    ['Business hotel, weekday', 'Neutral', 'Often lower — low weekend demand'],
                    ['Resort / leisure property', 'Yes for weekends/holidays', 'Risky unless truly off-peak'],
                  ].map(([scenario, early, lastMinute]) => (
                    <tr key={scenario} className="even:bg-gray-50/50">
                      <td className="px-4 py-3 text-gray-700 border border-gray-200">{scenario}</td>
                      <td className="px-4 py-3 text-gray-600 border border-gray-200">{early}</td>
                      <td className="px-4 py-3 text-gray-600 border border-gray-200">{lastMinute}</td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>
          </section>

          <section>
            <h2 className="text-2xl font-bold text-gray-900 mb-3">
              Day of week: does it matter when you search?
            </h2>
            <p className="text-gray-600">
              There is a persistent belief that searching on a Tuesday or Wednesday gets you lower
              prices. For flights this has some historical basis. For hotels, the evidence is much
              thinner.
            </p>
            <p className="text-gray-600 mt-3">
              What does hold up: <strong>when you stay</strong> matters more than when you search.
              Business-oriented hotels (city centre, near convention centres) tend to be significantly
              cheaper on Friday and Saturday nights when corporate travellers leave. Leisure-oriented
              hotels (beach resorts, countryside, ski) tend to be cheaper mid-week for the same reason
              in reverse.
            </p>
            <p className="text-gray-600 mt-3">
              Shifting your stay by a day or two — rather than the day you search — is where real
              savings come from on this dimension.
            </p>
          </section>

          <section>
            <h2 className="text-2xl font-bold text-gray-900 mb-3">
              The variable most travellers ignore: where you're searching from
            </h2>
            <p className="text-gray-600">
              Timing your booking is genuinely useful, but it's a second-order effect compared to
              <strong> geo-pricing</strong> — the practice of booking platforms showing different
              prices to users in different countries for the exact same room on the exact same night.
            </p>
            <p className="text-gray-600 mt-3">
              The price gap between the most expensive country and the cheapest country for a given
              hotel can be 20–40%. That dwarfs any savings from booking on a Tuesday vs. a Thursday,
              or from booking 10 weeks out vs. 8 weeks out.
            </p>

            <div className="mt-6 bg-purple-50 border border-purple-100 rounded-xl px-5 py-4">
              <p className="text-sm font-semibold text-gray-900 mb-2">A real example</p>
              <p className="text-sm text-gray-600 leading-relaxed">
                A 3-night stay at a mid-range hotel in Lisbon might appear as €210 when searched from
                the UK, €185 when searched from Portugal, and €168 when searched from Brazil — all
                on the same night, same room, via Booking.com. Booking 6 weeks early instead of 3
                weeks early might save €10. Searching from the right country saves €42.
              </p>
            </div>

            <p className="text-gray-600 mt-4">
              This doesn't mean timing is irrelevant — it means the two variables compound. The
              smartest approach is to find both the right timing window <em>and</em> the cheapest
              country to search from.
            </p>
          </section>

          <section>
            <h2 className="text-2xl font-bold text-gray-900 mb-3">
              How far in advance to book: a practical guide by destination type
            </h2>

            <div className="space-y-4">
              {[
                {
                  type: 'Major cities (Paris, Tokyo, New York, London)',
                  advice: 'Book 4–8 weeks out for regular travel. 3–6 months out for peak season and major events. Prices in these cities rarely drop at the last minute — demand is too consistent.',
                },
                {
                  type: 'Beach / resort destinations',
                  advice: 'Book 2–4 months out for peak season. For shoulder season, 3–6 weeks out often works well and prices can improve slightly as operators try to fill occupancy.',
                },
                {
                  type: 'Ski resorts',
                  advice: 'Book as early as possible for the main ski season — often 4–6 months. Last-minute ski accommodation is notoriously expensive and limited.',
                },
                {
                  type: 'Emerging / less-visited destinations',
                  advice: 'Much more flexible. Booking 2–3 weeks out is usually fine and you may benefit from operators lowering prices to fill rooms.',
                },
                {
                  type: 'Business travel cities',
                  advice: 'Mid-week rates are typically higher; weekend rates lower. If your travel has flexibility, even shifting by a day can yield 10–20% savings.',
                },
              ].map(({ type, advice }) => (
                <div key={type} className="bg-gray-50 rounded-xl p-4 border border-gray-100">
                  <p className="text-sm font-semibold text-gray-900 mb-1">{type}</p>
                  <p className="text-sm text-gray-600 leading-relaxed">{advice}</p>
                </div>
              ))}
            </div>
          </section>

          <section>
            <h2 className="text-2xl font-bold text-gray-900 mb-3">
              Cancellation policy: the underrated part of timing
            </h2>
            <p className="text-gray-600">
              One practical approach is to book early with a free cancellation rate, then check
              the price again closer to your stay. If the price has dropped (common in off-peak
              periods), cancel and rebook at the lower rate. Many travellers do this systematically
              and save 10–15% compared to committing to a non-refundable rate upfront.
            </p>
            <p className="text-gray-600 mt-3">
              The trade-off: free cancellation rates are almost always higher than non-refundable
              rates on the same booking. If you're confident about your dates and the destination is
              in high demand, locking in a non-refundable rate early typically beats the
              book-and-rebook approach.
            </p>
          </section>

          <section>
            <h2 className="text-2xl font-bold text-gray-900 mb-3">
              The practical checklist: how to get the lowest hotel price
            </h2>
            <ol className="space-y-3 list-none">
              {[
                { n: '01', text: 'Identify your destination type (peak/off-peak, leisure/business) and apply the timing guidance above.' },
                { n: '02', text: 'Check the price from multiple countries using a geo-pricing comparison tool — this is usually where the biggest gap is.' },
                { n: '03', text: 'Compare cancellation-flexible vs. non-refundable rates. If flexible, consider booking early and rechecking closer to your stay.' },
                { n: '04', text: 'Check mid-week vs. weekend rates if your travel dates have any flexibility.' },
                { n: '05', text: 'Compare across platforms (Booking.com, Agoda, Expedia) — the same property often varies between platforms due to different commission structures.' },
              ].map(({ n, text }) => (
                <li key={n} className="flex items-start gap-3">
                  <span className="shrink-0 w-7 h-7 rounded-full bg-brand-purple text-white text-xs font-bold flex items-center justify-center mt-0.5">{n}</span>
                  <p className="text-gray-600 text-sm leading-relaxed">{text}</p>
                </li>
              ))}
            </ol>
          </section>

          {/* CTA */}
          <div className="bg-brand-purple rounded-2xl p-7 text-center">
            <h3 className="text-lg font-bold text-white mb-2">
              Skip the guesswork — check the geo-price gap in seconds
            </h3>
            <p className="text-purple-200 text-sm mb-5 leading-relaxed">
              CahooTravel automatically checks your hotel across 100+ countries to find the cheapest
              available rate. Combine that with the right booking window and you'll rarely overpay.
            </p>
            <Link
              href="/"
              className="inline-flex items-center gap-2 bg-white text-brand-purple font-semibold text-sm px-6 py-3 rounded-xl hover:bg-purple-50 transition-colors"
            >
              Find the cheapest price for your hotel
              <svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
                <path strokeLinecap="round" strokeLinejoin="round" d="M17 8l4 4m0 0l-4 4m4-4H3" />
              </svg>
            </Link>
          </div>

        </div>
      </article>

      <BreadcrumbJsonLd
        items={[
          { name: 'Guides', path: '/guides' },
          { name: 'Best Time to Book a Hotel', path: '/guides/best-time-to-book-hotels' },
        ]}
      />
    </InternalPageTemplate>
  )
}
