import ResponsiveImage, {
  type ResponsiveImageProps,
} from '@components/molecules/images/responsive-image';
import Widget, { type WidgetProps } from '@components/molecules/layout/widget';
import { FC } from 'react';
import styles from './image-widget.module.scss';

export type Alignment = 'left' | 'center' | 'right';

export type Image = Pick<
  ResponsiveImageProps,
  'alt' | 'height' | 'src' | 'width'
>;

export type ImageWidgetProps = Pick<
  WidgetProps,
  'className' | 'expanded' | 'level' | 'title'
> & {
  /**
   * The content alignment.
   */
  alignment?: Alignment;
  /**
   * Add a caption to the image.
   */
  description?: ResponsiveImageProps['caption'];
  /**
   * An object describing the image.
   */
  image: Image;
  /**
   * Set additional classnames to the image wrapper.
   */
  imageClassName?: string;
  /**
   * Add a link to the image.
   */
  url?: ResponsiveImageProps['target'];
};

/**
 * ImageWidget component
 *
 * Renders a widget that print an image and an optional text.
 */
const ImageWidget: FC<ImageWidgetProps> = ({
  alignment = 'left',
  className = '',
  description,
  image,
  imageClassName = '',
  url,
  ...props
}) => {
  const alignmentClass = `widget--${alignment}`;

  return (
    <Widget className={`${styles[alignmentClass]} ${className}`} {...props}>
      <ResponsiveImage
        target={url}
        caption={description}
        className={`${styles.figure} ${imageClassName}`}
        {...image}
      />
    </Widget>
  );
};

export default ImageWidget;
andphilippot.com/log/src/components/Icons/Cog/Cog.module.scss'>log</a><a class='active' href='/www.armandphilippot.com/tree/src/components/Icons/Cog/Cog.module.scss?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>tree</a><a href='/www.armandphilippot.com/commit/src/components/Icons/Cog/Cog.module.scss?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>commit</a><a href='/www.armandphilippot.com/diff/src/components/Icons/Cog/Cog.module.scss?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>diff</a><a href='/www.armandphilippot.com/stats/src/components/Icons/Cog/Cog.module.scss'>stats</a></td><td class='form'><form class='right' method='get' action='/www.armandphilippot.com/log/src/components/Icons/Cog/Cog.module.scss'>
<input type='hidden' name='id' value='8966fde6ff520cfbe74c031c8b2e3a66d298b172'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/www.armandphilippot.com/tree/?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>root</a>/<a href='/www.armandphilippot.com/tree/src?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>src</a>/<a href='/www.armandphilippot.com/tree/src/components?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>components</a>/<a href='/www.armandphilippot.com/tree/src/components/Icons?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>Icons</a>/<a href='/www.armandphilippot.com/tree/src/components/Icons/Cog?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>Cog</a>/<a href='/www.armandphilippot.com/tree/src/components/Icons/Cog/Cog.module.scss?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>Cog.module.scss</a></div><div class='content'>blob: a861f0c5095426479e447eeaa7d222cd6ef59541 (<a href='/www.armandphilippot.com/plain/src/components/Icons/Cog/Cog.module.scss?id=8966fde6ff520cfbe74c031c8b2e3a66d298b172'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
</pre></td>
<td class='lines'><pre><code>