"use client";
import { WalletIcon } from "lucide-react";
import React from "react";
import AppAvatar from "src/components/AppAvatar";
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
useComboboxAnchor,
} from "src/components/ui/combobox";
import { InputGroupAddon } from "src/components/ui/input-group";
import { Label } from "src/components/ui/label";
import { PAY_FROM_SELECT_APPS_LIMIT } from "src/constants";
import { useApps } from "src/hooks/useApps";
import { getAppDisplayName } from "src/lib/utils";
import { App } from "src/types";
const LIGHTNING_BALANCE = "lightning-balance";
const LIGHTNING_BALANCE_LABEL = "Lightning Balance";
type PayFromOption = {
value: string;
label: string;
app?: App;
};
type Props = {
appId?: number;
onChange(appId: number | undefined): void;
};
function LightningOption() {
return (
{LIGHTNING_BALANCE_LABEL}
);
}
function AppOption({ app }: { app: App }) {
return (
{getAppDisplayName(app.name)}
);
}
export default function PayFromSelect({ appId, onChange }: Props) {
const anchorRef = useComboboxAnchor();
const [search, setSearch] = React.useState("");
const { data: appsData } = useApps(PAY_FROM_SELECT_APPS_LIMIT, undefined, {
name: search,
});
const apps = React.useMemo(
() =>
[...(appsData?.apps || [])]
.filter((app) => app.scopes.includes("pay_invoice"))
.sort((a, b) =>
getAppDisplayName(a.name).localeCompare(getAppDisplayName(b.name))
),
[appsData?.apps]
);
const options = React.useMemo(
() => [
{ value: LIGHTNING_BALANCE, label: LIGHTNING_BALANCE_LABEL },
...apps.map((app) => ({
value: app.id.toString(),
label: getAppDisplayName(app.name),
app,
})),
],
[apps]
);
const selectedOption = options.find((opt) =>
appId ? opt.value === appId.toString() : undefined
);
return (
option.value}
onInputValueChange={setSearch}
onValueChange={(option) =>
onChange(
option?.value === LIGHTNING_BALANCE
? undefined
: Number(option?.value)
)
}
>
{selectedOption?.app ? (
) : (
)}
No connections found.
{(option: PayFromOption) => (
{option.app ? (
) : (
)}
)}
);
}