/* eslint-disable import/order */
<% icons.forEach((icon) => { -%>
import { <%= icon.Icon %>SVG } from './<%= icon.Icon %>';
<% }); %>

import type { IconProps } from '../types';
import type { SvgStringOpts } from '../svgString';

export const svgMap = {
<% icons.forEach((icon) => { -%>
  <%= icon.name %>: <%= icon.Icon %>SVG,
<% }); %>
};

export type IconSVGName = keyof typeof svgMap;
type Opts = IconProps & {
  name: IconSVGName;
  xclass?: string;
};

const defaultOpts: Opts = {
  name: 'epilot',
  size: 24,
  fill: 'currentColor',
};

export const svgIcon = (opts: Opts): string => {
  const { name, ...restOpts } = {
    ...defaultOpts,
    ...opts,
  };

  const svg = svgMap[name];

  if (!svg) return '';

  // Each *SVG builder already applies size/width/height/fill/xclass/variant,
  // so no DOM parsing is needed.
  return svg(restOpts as SvgStringOpts);
};
