var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import { jsx as _jsx } from "react/jsx-runtime";
import { implementRuntimeComponent } from '@subscan/widget-runtime';
import { Type } from '@sinclair/typebox';
import { PRESET_PROPERTY_CATEGORY } from '@subscan/widget-shared';
import { css } from '@emotion/css';
import { VERSION } from 'config/constants';
import { FALLBACK_METADATA } from 'utils/widget-helper';
import { Icons } from 'components/Svg/Icons';
var IconPropsSpec = Type.Object({
    name: Type.KeyOf(Type.Object(Icons), {
        title: 'Name',
    }),
    spin: Type.Boolean({
        title: 'Spin',
    }),
});
export default implementRuntimeComponent({
    version: VERSION.Core,
    metadata: __assign(__assign({}, FALLBACK_METADATA), { name: 'icon', displayName: 'Icon', description: 'Awesome Icon.', exampleProperties: {
            name: 'barchart',
            spin: false,
        }, annotations: {
            category: PRESET_PROPERTY_CATEGORY.Basic,
        } }),
    spec: {
        properties: IconPropsSpec,
        state: Type.Object({
            isHover: Type.Boolean(),
        }),
        methods: {},
        slots: {},
        styleSlots: ['content'],
        events: ['onClick'],
    },
})(function (_a) {
    var _b = _a.name, name = _b === void 0 ? 'barchart' : _b, spin = _a.spin, customStyle = _a.customStyle, callbackMap = _a.callbackMap, mergeState = _a.mergeState;
    var Component = Icons[name];
    var onMouseEnter = function () {
        mergeState({
            isHover: true,
        });
    };
    var onMouseLeave = function () {
        mergeState({
            isHover: false,
        });
    };
    var onClick = function () {
        var _a;
        (_a = callbackMap === null || callbackMap === void 0 ? void 0 : callbackMap.onClick) === null || _a === void 0 ? void 0 : _a.call(callbackMap);
    };
    if (!name) {
        return null;
    }
    return (_jsx(Component, { className: css(customStyle === null || customStyle === void 0 ? void 0 : customStyle.content), onClick: onClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, spin: spin }));
});
