import React from "react";
import { TrendUp, TrendDown } from "@phosphor-icons/react";

export default function StatCard({
  title,
  value,
  change,
  changeType = "positive",
  icon: Icon,
  iconColor = "brown",
  prefix = "",
  suffix = "",
  trend = null,
}) {
  const colorMap = {
    brown: "bg-primary-500",
    green: "bg-green-500",
    purple: "bg-purple-500",
    orange: "bg-orange-500",
    red: "bg-red-500",
    gray: "bg-gray-500",
  };

  const isPositive = changeType === "positive";
  const TrendIcon =
    trend === "up" ? TrendUp : trend === "down" ? TrendDown : null;

  return (
    <div className="bg-white rounded-xl shadow-sm border border-gray-100 p-6 hover:shadow-md transition-shadow duration-200">
      <div className="flex items-center justify-between">
        <div className="flex-1">
          <p className="text-sm font-medium text-gray-600 mb-1">{title}</p>
          <div className="flex items-baseline gap-2">
            <h3 className="text-3xl font-bold text-gray-900">
              {prefix}
              {typeof value === "number" ? value.toLocaleString() : value}
              {suffix}
            </h3>
            {change !== undefined && (
              <span
                className={`inline-flex items-center gap-1 text-sm font-semibold ${
                  isPositive ? "text-green-600" : "text-red-600"
                }`}
              >
                {TrendIcon && <TrendIcon size={16} weight="bold" />}
                {change}%
              </span>
            )}
          </div>
          {change !== undefined && (
            <p className="text-xs text-gray-500 mt-2">
              {isPositive ? "Up" : "Down"} from last month
            </p>
          )}
        </div>
        {Icon && (
          <div className={`${colorMap[iconColor]} rounded-xl p-3 text-white`}>
            <Icon size={28} weight="duotone" />
          </div>
        )}
      </div>
    </div>
  );
}
