import React from 'react';

import type { IAgentAnalyticsTrend } from '../../service/agent-analytics/agent-analytics.interface';

import TrendBadge from './TrendBadge';
import InfoTooltip from './InfoTooltip';

interface KPICardProps {
  icon: React.ElementType;
  label: string;
  value: string | number;
  trend?: IAgentAnalyticsTrend;
  suffix?: string;
  tooltip?: string;
}

const KPICard = ({
  icon: IconComp,
  label,
  value,
  trend,
  suffix,
  tooltip,
}: KPICardProps): JSX.Element => (
  <div className="flex flex-col justify-between rounded-xl border border-gray-200 bg-white p-5 shadow-sm transition-all hover:border-gray-300 hover:shadow-md">
    <div className="mb-4 flex items-start justify-between">
      <div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg border border-gray-100 bg-gray-50 text-gray-700">
        <IconComp className="h-5 w-5" aria-hidden="true" />
      </div>

      {tooltip && (
        <div className="text-gray-400 transition-colors hover:text-gray-700">
          <InfoTooltip text={tooltip} />
        </div>
      )}
    </div>

    <div className="flex flex-col">
      <h3 className="text-sm font-medium leading-snug text-gray-500">
        {label}
      </h3>

      <div className="mt-1 flex items-baseline gap-1.5">
        <span className="text-2xl font-bold tracking-tight text-gray-900 xl:text-3xl">
          {value}
        </span>
        {suffix && (
          <span className="text-sm font-medium text-gray-500">{suffix}</span>
        )}
      </div>
    </div>

    {trend && (
      <div className="mt-4 border-t border-gray-100 pt-4">
        <TrendBadge delta={trend} />
      </div>
    )}
  </div>
);

export default KPICard;
