import { jsx, jsxs } from "react/jsx-runtime";
import { cn } from "@uipath/apollo-wind";
import { ChevronDown } from "lucide-react";
import { memo, useCallback } from "react";
const SelectField_SelectField = /*#__PURE__*/ memo(function({ field, value, onChange, error }) {
    const handleChange = useCallback((e)=>{
        const raw = e.target.value;
        const matched = field.options?.find((o)=>String(o.value) === raw);
        onChange(matched ? matched.value : raw);
    }, [
        field.options,
        onChange
    ]);
    const selectId = `field-${field.key}`;
    return /*#__PURE__*/ jsxs("div", {
        className: "flex flex-col gap-1",
        children: [
            /*#__PURE__*/ jsx("label", {
                htmlFor: selectId,
                className: "text-[13px] text-(--canvas-foreground-de-emp)",
                children: field.label
            }),
            /*#__PURE__*/ jsxs("div", {
                className: "relative",
                children: [
                    /*#__PURE__*/ jsxs("select", {
                        id: selectId,
                        className: cn('nodrag w-full px-3 py-2 pr-8 text-[13px] border border-(--canvas-border) rounded bg-(--canvas-background) text-(--canvas-foreground) outline-none transition-colors appearance-none cursor-pointer', 'focus:border-(--canvas-primary)', 'disabled:opacity-50 disabled:cursor-not-allowed', error && 'border-(--canvas-error)'),
                        value: value ?? field.defaultValue ?? '',
                        onChange: handleChange,
                        disabled: field.disabled,
                        children: [
                            field.placeholder && /*#__PURE__*/ jsx("option", {
                                value: "",
                                disabled: true,
                                children: field.placeholder
                            }),
                            field.options?.map((option)=>/*#__PURE__*/ jsx("option", {
                                    value: option.value,
                                    children: option.label
                                }, option.value))
                        ]
                    }),
                    /*#__PURE__*/ jsx(ChevronDown, {
                        size: 14,
                        className: "pointer-events-none absolute right-2.5 top-1/2 -translate-y-1/2 text-(--canvas-foreground-de-emp)",
                        "aria-hidden": true
                    })
                ]
            }),
            field.helpText && /*#__PURE__*/ jsx("span", {
                className: "text-[12px] text-(--canvas-foreground-de-emp) block",
                children: field.helpText
            }),
            error && /*#__PURE__*/ jsx("span", {
                className: "text-[12px] text-(--canvas-error-text) block",
                children: error
            })
        ]
    });
});
export { SelectField_SelectField as SelectField };
