//
// Copyright 2021 DXOS.org
//
import React from 'react';
import { PublicKey } from '@dxos/react-client';
import { Select } from '@dxos/react-ui';
import { humanize } from '@dxos/util';
export const PublicKeySelector = ({ placeholder, getLabel = humanize, keys, value, onChange, }) => {
    return (React.createElement(Select.Root, { value: value?.toHex(), onValueChange: (id) => {
            id && onChange?.(PublicKey.fromHex(id));
        } },
        React.createElement(Select.TriggerButton, { placeholder: placeholder }),
        React.createElement(Select.Portal, null,
            React.createElement(Select.Content, null,
                React.createElement(Select.Viewport, null, removeDuplicates(keys).map((key) => (React.createElement(Select.Option, { key: key.toHex(), value: key.toHex() },
                    React.createElement("div", { className: 'flex items-center gap-2' },
                        React.createElement("span", { className: 'font-mono text-neutral-250' }, key.truncate()),
                        getLabel(key)))))),
                React.createElement(Select.Arrow, null)))));
};
// TODO(burdon): Factor out.
const removeDuplicates = (keys) => keys.reduce((result, key) => {
    if (key !== undefined && !result.some((existing) => existing.equals(key))) {
        result.push(key);
    }
    return result;
}, []);
//# sourceMappingURL=PublicKeySelector.js.map