import { jsx, jsxs } from "react/jsx-runtime";
import { useCallback, useMemo, useState } from "react";
import { Select } from "antd";
import { useSchemaInitializerItem } from "../context/index.mjs";
import { SchemaInitializerItem } from "./SchemaInitializerItem.mjs";
const SchemaInitializerSelect = (props)=>{
    const { title, options, value, onChange, openOnHover, onClick: _onClick, ...others } = props;
    const [open, setOpen] = useState(false);
    const onClick = useCallback(function() {
        for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++)args[_key] = arguments[_key];
        setOpen(false);
        null == _onClick || _onClick(...args);
    }, [
        setOpen,
        _onClick
    ]);
    const onMouseEnter = useCallback(()=>setOpen(true), []);
    const moreProps = useMemo(()=>openOnHover ? {
            onMouseEnter,
            open
        } : {}, [
        onMouseEnter,
        open,
        openOnHover
    ]);
    return /*#__PURE__*/ jsx(SchemaInitializerItem, {
        ...others,
        children: /*#__PURE__*/ jsxs("div", {
            style: {
                alignItems: 'center',
                display: 'flex',
                justifyContent: 'space-between'
            },
            children: [
                title,
                /*#__PURE__*/ jsx(Select, {
                    "data-testid": "antd-select",
                    popupMatchSelectWidth: false,
                    bordered: false,
                    defaultValue: value,
                    onChange: function() {
                        for(var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++)arg[_key] = arguments[_key];
                        return setOpen(false), onChange(...arg);
                    },
                    options: options,
                    style: {
                        textAlign: 'right',
                        minWidth: 100
                    },
                    onClick: onClick,
                    ...moreProps
                })
            ]
        })
    });
};
const SchemaInitializerSelectInternal = ()=>{
    const itemConfig = useSchemaInitializerItem();
    return /*#__PURE__*/ jsx(SchemaInitializerSelect, {
        ...itemConfig
    });
};
export { SchemaInitializerSelect, SchemaInitializerSelectInternal };
