import { ResourceListActions } from "@/components/common/ResourceListActions";

export interface ReportActionsProps {
  isLoading: boolean;
  onRefresh: () => void;
  /** Omit for reports without a filter panel. */
  onToggleFilters?: () => void;
  showFilters?: boolean;
  activeFilterCount?: number;
  /** Shown to the left of the buttons, e.g. on the overall summary report. */
  lastRefreshedAt?: string | null;
}

/**
 * The toolbar every report page puts in its `PageHeader`: Filters (when the
 * report has any) plus Refresh.
 */
export function ReportActions({
  isLoading,
  onRefresh,
  onToggleFilters,
  showFilters = false,
  activeFilterCount = 0,
  lastRefreshedAt,
}: ReportActionsProps) {
  const actions = (
    <ResourceListActions
      isLoading={isLoading}
      onRefresh={onRefresh}
      refreshVariant={onToggleFilters ? "primary" : "secondary"}
      filters={
        onToggleFilters
          ? { show: showFilters, count: activeFilterCount, onToggle: onToggleFilters }
          : undefined
      }
    />
  );

  if (!lastRefreshedAt) return actions;

  return (
    <div className="flex items-center gap-3 text-right">
      <span className="text-xs text-muted-foreground">
        Last refreshed: {new Date(lastRefreshedAt).toLocaleString()}
      </span>
      {actions}
    </div>
  );
}
