"use client";

import { cn } from "@turbostarter/ui";

import type { BusinessData } from "./wizard";

interface BusinessCardProps {
  business: BusinessData;
  onClick?: () => void;
  selected?: boolean;
  className?: string;
}

export const BusinessCard = ({
  business,
  onClick,
  selected,
  className,
}: BusinessCardProps) => {
  return (
    <button
      type="button"
      onClick={onClick}
      className={cn(
        "bg-background flex w-full items-start gap-4 rounded-xl border p-4 text-left transition-colors",
        onClick && "hover:border-primary/50 cursor-pointer",
        selected && "border-primary bg-primary/5",
        className,
      )}
    >
      <div className="bg-primary/10 flex size-10 shrink-0 items-center justify-center rounded-lg">
        <svg
          className="text-primary size-5"
          fill="none"
          viewBox="0 0 24 24"
          stroke="currentColor"
          strokeWidth={1.5}
        >
          <path
            strokeLinecap="round"
            strokeLinejoin="round"
            d="M13.5 21v-7.5a.75.75 0 0 1 .75-.75h3a.75.75 0 0 1 .75.75V21m-4.5 0H2.36m11.14 0H18m0 0h3.64m-1.39 0V9.349M3.75 21V9.349m0 0a3.001 3.001 0 0 0 3.75-.615A2.993 2.993 0 0 0 9.75 9.75c.896 0 1.7-.393 2.25-1.016a2.993 2.993 0 0 0 2.25 1.016c.896 0 1.7-.393 2.25-1.015a3.001 3.001 0 0 0 3.75.614m-16.5 0a3.004 3.004 0 0 1-.621-4.72l1.189-1.19A1.5 1.5 0 0 1 5.378 3h13.243a1.5 1.5 0 0 1 1.06.44l1.19 1.189a3 3 0 0 1-.621 4.72M6.75 18h3.75a.75.75 0 0 0 .75-.75V13.5a.75.75 0 0 0-.75-.75H6.75a.75.75 0 0 0-.75.75v3.75c0 .414.336.75.75.75Z"
          />
        </svg>
      </div>

      <div className="flex min-w-0 flex-1 flex-col gap-0.5">
        <span className="text-foreground truncate font-medium">
          {business.name}
        </span>
        <span className="text-muted-foreground truncate text-sm">
          {business.address}
        </span>
        <div className="mt-1 flex items-center gap-3">
          {business.rating > 0 && (
            <span className="flex items-center gap-1 text-sm">
              <svg
                className="size-3.5 text-amber-500"
                fill="currentColor"
                viewBox="0 0 20 20"
              >
                <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
              </svg>
              <span className="text-foreground font-medium">
                {business.rating}
              </span>
            </span>
          )}
          {business.review_count > 0 && (
            <span className="text-muted-foreground text-sm">
              ({business.review_count})
            </span>
          )}
          {business.category && (
            <span className="text-muted-foreground text-xs">
              {business.category}
            </span>
          )}
        </div>
      </div>
    </button>
  );
};
