---
import { Icon } from 'astro-icon/components';

interface Props {
  views: number;
  className?: string;
}

const { views, className = '' } = Astro.props;

const formatViews = (n: number) => {
  if (n >= 1000) {
    return (n / 1000).toFixed(1).replace(/\.0$/, '') + 'k';
  }
  return n.toString();
};
---

<div class={`post-view-counter ${className}`}>
  <Icon name="eye" class="view-icon" />
  <span class="view-count">{formatViews(views)}</span>
</div>

<style>
  .post-view-counter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .view-icon {
    width: 1.1rem;
    height: 1.1rem;
    color: #eac26e;
  }

  .view-count {
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
  }
</style>