---

import { Image } from 'astro:assets';
import type { ComponentProps } from 'astro/types';
import { twMerge } from '@/utils/twMerge';

type Props = ComponentProps<typeof Image>;
const { class: className, src, ...rest } = Astro.props;

const imgClass = twMerge('my-8 h-auto max-w-full', className);
---

{
  typeof src === "string" ? (
    src.startsWith("http") ? (
      <img class={imgClass} src={src} {...rest} />
    ) : (
      // Non-HTTP string: public path or relative URL. Astro's Image needs
      // inferSize to skip the width/height requirement for string src.
      <Image class={imgClass} inferSize={true} src={src} {...rest} />
    )
  ) : (
    // ImageMetadata (ESM-imported image): width/height come from metadata,
    // no inferSize needed.
    <Image class={imgClass} src={src} {...rest} />
  )
}
