import Link from "@/components/Link";
import type { BlogPost } from "@/content/blog-posts";
import { signupHref } from "@/lib/site";

const shortDate = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", year: "numeric", timeZone: "UTC" });
const longDate = new Intl.DateTimeFormat("en-US", { month: "long", day: "numeric", year: "numeric", timeZone: "UTC" });

export const blogDate = (post: BlogPost) => shortDate.format(new Date(`${post.date}T00:00:00Z`));
export const blogLongDate = (post: BlogPost) => longDate.format(new Date(`${post.date}T00:00:00Z`));

export function BlogCard({ post, showExcerpt = true }: { post: BlogPost; showExcerpt?: boolean }) {
  return (
    <Link className="an-bcard" href={`/blog/${post.slug}`}>
      <span className="an-bcard__img"><img src={post.image} alt={post.imageAlt} width={1600} height={1000} loading="lazy" /></span>
      <span className="an-bcard__body">
        <span className="an-bcard__meta"><time dateTime={post.date}>{blogDate(post)}</time><span>{post.minutes} min read</span></span>
        <h3>{post.title}</h3>
        {showExcerpt ? <p>{post.excerpt}</p> : null}
      </span>
    </Link>
  );
}

export function BlogCta() {
  return (
    <section className="an-section an-blog-ctasec">
      <div className="an-wrap">
        <div className="an-blog-cta an-reveal">
          <div>
            <h2 className="an-h2">Ready to put these ideas to work?</h2>
            <p>Tell us about your goals and we’ll help you find the right channel mix.</p>
          </div>
          <div className="an-actions">
            <a className="an-btn an-btn--white" href={signupHref} data-track="signup_click" data-track-location="blog_cta">Start Advertising</a>
            <Link className="an-btn an-btn--ghost-light" href="/contact" data-track="sales_click" data-track-location="blog_cta">Talk to Sales</Link>
          </div>
        </div>
      </div>
    </section>
  );
}
