/**
 * Centralized SVG icon constants and getter functions.
 *
 * Uses Lucide icons (https://lucide.dev) — MIT-licensed, 24×24 stroke icons.
 * SVG path data lives in icon-paths.js; this module wraps them with the
 * <svg> tag and exports named constants for use across the app.
 *
 * Import icons from this module instead of using inline emoji literals.
 */

import * as P from './icon-paths.ts';

// ── SVG wrapper ────────────────────────────────────────────
const _svg = (d: string): string => `<svg class="icon" viewBox="0 0 24 24">${d}</svg>`;

// ── Type-resolution maps (private) ──────────────────────────
const _targetTypeIcons        = { led: _svg(P.lightbulb), wled: _svg(P.lightbulb), key_colors: _svg(P.palette) };
const _pictureSourceTypeIcons = { raw: _svg(P.monitor), processed: _svg(P.palette), static_image: _svg(P.image), video: _svg(P.film) };
const _colorStripTypeIcons    = {
    picture_advanced: _svg(P.monitor),
    static: _svg(P.palette), color_cycle: _svg(P.refreshCw), gradient: _svg(P.rainbow),
    effect: _svg(P.zap), composite: _svg(P.link),
    mapped: _svg(P.mapPin), mapped_zones: _svg(P.mapPin),
    audio: _svg(P.music), audio_visualization: _svg(P.music),
    api_input: _svg(P.send),
    notification: _svg(P.bellRing),
    daylight: _svg(P.sun),
    candlelight: _svg(P.flame),
    weather: _svg(P.cloudSun),
    processed: _svg(P.sparkles),
};
const _valueSourceTypeIcons   = {
    static: _svg(P.layoutDashboard), animated: _svg(P.refreshCw), audio: _svg(P.music),
    adaptive_time: _svg(P.clock), adaptive_scene: _svg(P.cloudSun),
    daylight: _svg(P.sun),
};
const _audioSourceTypeIcons   = { mono: _svg(P.mic), multichannel: _svg(P.volume2), band_extract: _svg(P.activity) };
const _deviceTypeIcons        = {
    wled: _svg(P.wifi), adalight: _svg(P.usb), ambiled: _svg(P.usb),
    mqtt: _svg(P.send), ws: _svg(P.globe), openrgb: _svg(P.palette),
    dmx: _svg(P.radio), mock: _svg(P.wrench),
    espnow: _svg(P.radio), hue: _svg(P.lightbulb), usbhid: _svg(P.usb),
    spi: _svg(P.plug), chroma: _svg(P.zap), gamesense: _svg(P.target),
};
const _engineTypeIcons        = {
    mss: _svg(P.monitor), dxcam: _svg(P.zap), bettercam: _svg(P.rocket),
    camera: _svg(P.camera), scrcpy: _svg(P.smartphone), wgc: _svg(P.film),
};
const _audioEngineTypeIcons   = { wasapi: _svg(P.volume2), sounddevice: _svg(P.mic) };

// ── Type-resolution getters ─────────────────────────────────

/** Target type → icon (fallback: zap) */
export function getTargetTypeIcon(targetType: string): string {
    return _targetTypeIcons[targetType] || _svg(P.zap);
}

/** Picture source / stream type → icon (fallback: tv) */
export function getPictureSourceIcon(streamType: string): string {
    return _pictureSourceTypeIcons[streamType] || _svg(P.tv);
}

/** Color strip source type → icon (fallback: film) */
export function getColorStripIcon(sourceType: string): string {
    return _colorStripTypeIcons[sourceType] || _svg(P.film);
}

/** Value source type → icon (fallback: sliders) */
export function getValueSourceIcon(sourceType: string): string {
    return _valueSourceTypeIcons[sourceType] || _svg(P.slidersHorizontal);
}

/** Audio source type → icon (fallback: music) */
export function getAudioSourceIcon(sourceType: string): string {
    return _audioSourceTypeIcons[sourceType] || _svg(P.music);
}

/** Device type → icon (fallback: lightbulb) */
export function getDeviceTypeIcon(deviceType: string): string {
    return _deviceTypeIcons[deviceType] || _svg(P.lightbulb);
}

/** Capture engine type → icon (fallback: rocket) */
export function getEngineIcon(engineType: string): string {
    return _engineTypeIcons[engineType] || _svg(P.rocket);
}

/** Audio engine type → icon (fallback: music) */
export function getAudioEngineIcon(engineType: string): string {
    return _audioEngineTypeIcons[engineType] || _svg(P.music);
}

// ── Entity-kind constants ───────────────────────────────────

export const ICON_AUTOMATION    = _svg(P.clipboardList);
export const ICON_DEVICE        = _svg(P.monitor);
export const ICON_TARGET        = _svg(P.zap);
export const ICON_VALUE_SOURCE  = _svg(P.hash);

// ── Template-kind constants ─────────────────────────────────

export const ICON_TEMPLATE          = _svg(P.clipboardList);
export const ICON_CAPTURE_TEMPLATE  = _svg(P.camera);
export const ICON_PP_TEMPLATE       = _svg(P.wrench);
export const ICON_PATTERN_TEMPLATE  = _svg(P.fileText);
export const ICON_AUDIO_TEMPLATE    = _svg(P.music);
export const ICON_CSPT              = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/></svg>';

// ── Action constants ────────────────────────────────────────

export const ICON_CLONE         = _svg(P.copy);
export const ICON_EDIT          = _svg(P.pencil);
export const ICON_TEST          = _svg(P.flaskConical);
export const ICON_START         = _svg(P.play);
export const ICON_STOP          = _svg(P.power);
export const ICON_STOP_PLAIN    = _svg(P.power);
export const ICON_PAUSE         = _svg(P.pause);
export const ICON_SETTINGS      = _svg(P.settings);
export const ICON_CALIBRATION   = _svg(P.ruler);

// ── Misc badge constants ────────────────────────────────────

export const ICON_AUDIO_LOOPBACK = _svg(P.volume2);
export const ICON_AUDIO_INPUT    = _svg(P.mic);
export const ICON_CLOCK          = _svg(P.clock);
export const ICON_WARNING        = _svg(P.triangleAlert);
export const ICON_OK             = _svg(P.circleCheck);
export const ICON_LINK_SOURCE    = _svg(P.tv);
export const ICON_LED            = _svg(P.lightbulb);
export const ICON_FPS            = _svg(P.zap);
export const ICON_WEB            = _svg(P.globe);
export const ICON_OVERLAY        = _svg(P.eye);
export const ICON_LED_PREVIEW    = _svg(P.layoutDashboard);
export const ICON_AUTOSTART      = _svg(P.star);

// ── UI / header / modal icons ───────────────────────────────

export const ICON_SEARCH         = _svg(P.search);
export const ICON_MOON           = _svg(P.moon);
export const ICON_SUN            = _svg(P.sun);
export const ICON_KEY            = _svg(P.keyRound);
export const ICON_LOGOUT         = _svg(P.logOut);
export const ICON_EYE            = _svg(P.eye);
export const ICON_EYE_OFF        = _svg(P.eyeOff);
export const ICON_HELP           = _svg(P.circleHelp);
export const ICON_DASHBOARD      = _svg(P.layoutDashboard);

// ── Card badge icons ────────────────────────────────────────

export const ICON_PALETTE        = _svg(P.palette);
export const ICON_RAINBOW        = _svg(P.rainbow);
export const ICON_REFRESH        = _svg(P.refreshCw);
export const ICON_LINK           = _svg(P.link);
export const ICON_MAP_PIN        = _svg(P.mapPin);
export const ICON_MUSIC          = _svg(P.music);
export const ICON_TIMER          = _svg(P.timer);
export const ICON_MONITOR        = _svg(P.monitor);
export const ICON_GLOBE          = _svg(P.globe);
export const ICON_RADIO          = _svg(P.radio);
export const ICON_PLUG           = _svg(P.plug);
export const ICON_FILM           = _svg(P.film);
export const ICON_FILE_TEXT      = _svg(P.fileText);
export const ICON_TARGET_ICON    = _svg(P.target);
export const ICON_TRENDING_UP    = _svg(P.trendingUp);
export const ICON_ACTIVITY       = _svg(P.activity);
export const ICON_MOVE_VERTICAL  = _svg(P.moveVertical);
export const ICON_SUN_DIM        = _svg(P.sunDim);
export const ICON_CAMERA         = _svg(P.camera);
export const ICON_WRENCH         = _svg(P.wrench);
export const ICON_SPARKLES       = _svg(P.sparkles);
export const ICON_FAST_FORWARD   = _svg(P.fastForward);
export const ICON_ROTATE_CW      = _svg(P.rotateCw);
export const ICON_ROTATE_CCW     = _svg(P.rotateCcw);
export const ICON_DOWNLOAD       = _svg(P.download);
export const ICON_UNDO           = _svg(P.undo2);
export const ICON_SCENE          = _svg(P.sparkles);
export const ICON_CAPTURE        = _svg(P.camera);
export const ICON_BELL           = _svg(P.bellRing);
export const ICON_THERMOMETER    = _svg(P.thermometer);
export const ICON_CPU            = _svg(P.cpu);
export const ICON_KEYBOARD       = _svg(P.keyboard);
export const ICON_MOUSE          = _svg(P.mouse);
export const ICON_HEADPHONES     = _svg(P.headphones);
export const ICON_TRASH          = _svg(P.trash2);
export const ICON_LIST_CHECKS    = _svg(P.listChecks);
export const ICON_CIRCLE_OFF     = _svg(P.circleOff);
export const ICON_EXTERNAL_LINK  = _svg(P.externalLink);
export const ICON_X              = _svg(P.xIcon);
export const ICON_FILE_UP        = _svg(P.fileUp);
export const ICON_FILE_AUDIO     = _svg(P.fileAudio);
export const ICON_ASSET          = _svg(P.packageIcon);
export const ICON_HEART          = _svg(P.heart);
export const ICON_GITHUB         = _svg(P.github);

/** Asset type → icon (fallback: file) */
export function getAssetTypeIcon(assetType: string): string {
    const map: Record<string, string> = {
        sound: _svg(P.volume2),
        image: _svg(P.image),
        video: _svg(P.film),
        other: _svg(P.fileText),
    };
    return map[assetType] || _svg(P.fileText);
}
