import { useMemo, useState } from "react";
import type { ThirdwebClient } from "../../../../../client/client.js";
import { iconSize, type Theme } from "../../../../core/design-system/index.js";
import type {
SupportedNFTs,
SupportedTokens,
} from "../../../../core/utils/defaultTokens.js";
import { Container, Line, ModalHeader } from "../../components/basic.js";
import { Spacer } from "../../components/Spacer.js";
import Tabs from "../../components/Tabs.js";
import { CoinsIcon } from "../icons/CoinsIcon.js";
import { ImageIcon } from "../icons/ImageIcon.js";
import type { ConnectLocale } from "../locale/types.js";
import type { WalletDetailsModalScreen } from "./types.js";
import { ViewNFTsContent } from "./ViewNFTs.js";
import { ViewTokensContent } from "./ViewTokens.js";
/**
* @internal
*/
export type AssetTabs = "token" | "nft";
const TokenTab = {
label: (
Tokens
),
value: "Tokens",
};
const NftTab = {
label: (
NFTs
),
value: "NFTs",
};
/**
* @internal
*/
export function ViewAssets(props: {
supportedTokens?: SupportedTokens;
supportedNFTs?: SupportedNFTs;
theme: Theme | "light" | "dark";
onBack: () => void;
setScreen: (screen: WalletDetailsModalScreen) => void;
client: ThirdwebClient;
connectLocale: ConnectLocale;
assetTabs?: AssetTabs[];
}) {
const { connectLocale } = props;
const options = useMemo(() => {
if (!props.assetTabs) {
return [TokenTab, NftTab];
}
if (!props.assetTabs.length) {
return [];
}
const tabs = [];
for (const item of props.assetTabs) {
if (item === "token") {
tabs.push(TokenTab);
} else if (item === "nft") {
tabs.push(NftTab);
}
}
return tabs;
}, [props.assetTabs]);
// Since `options` is now a dynamic value, the default active tab is set to the value of the first tab in `options`
const [activeTab, setActiveTab] = useState(options[0]?.value || "Tokens");
return (
{activeTab === "Tokens" && (
)}
{activeTab === "NFTs" && (
)}
);
}