import React from "react";
import CardRenderer from "../Cards/CardRenderer";
import { cardTokens } from "../../theme/cardTokens";
import { getTemplateSpecForPost, adaptPostToTemplateData } from "../Map/templateSpecs";

export default function PostCard({ post, selected, onSelect }) {
  const spec = getTemplateSpecForPost(post, "mini");
  const data = adaptPostToTemplateData(post);

  return (
    <article
      className={"post-card" + (selected ? " selected" : "")}
      onClick={() => onSelect && onSelect(post)}
      style={{ padding: 6 }}
    >
      <div className="sw-wall-mini">
        <CardRenderer
          spec={spec}
          data={data}
          themeTokens={cardTokens.blue}
          onAction={(action, value) => {
            if (action?.type === "open_url" && value) window.open(value, "_blank");
          }}
        />
      </div>
    </article>
  );
}
