import { createSlice } from "@reduxjs/toolkit";
import type { Token } from "../types";
import type { Chain } from "./globalSlice";

const initialState: TokenSelectorParams = {
	isVisible: false,
	data: null,
};

const tokenSelectorSlice = createSlice({
	name: "tokenSelector",
	initialState,
	reducers: {
		setTokenSelectorData: (state, action) => {
			state.isVisible = action.payload.isVisible;
			state.data = action.payload.data;
		},
	},
});

export interface TokenSelectorParams {
	isVisible: boolean;
	data: {
		id: number;
		chains: Chain[];
		tokens: { [chainId: string]: Token[] };
		activeChain?: Chain | "all";
		activeToken?: Token;
		isSourceTokenSelector?: boolean;
		tokensToDisable?: { [x: number]: string[] };
	} | null;
}

export const { setTokenSelectorData } = tokenSelectorSlice.actions;
export default tokenSelectorSlice.reducer;
