import gradio as gr
from modules.rebalancing import rebalancing_tool
from modules.utils import currency_codes, current_time

examples = [
    ["KRW", "458730 KRW 580 [8],\n368590 KRW 80 [2],", 507977],
]

# Define Gradio components
main_currency = gr.Dropdown(
    label="Main Currency",
    choices=currency_codes,
    value="KRW",
    # info="Assets converted to main currency"
)
title_setup = gr.Markdown(f"""<h3 class='h3_title'>Re-Balancing Calculator</h3>""")
holdings = gr.Textbox(
    label="Portfolio [Target]",
    lines=2,
    # info="Format: Ticker Currency Quantity [Target_Weight], ...",
    placeholder="Format: Ticker Currency Quantity [Target_Ratio], ...",
    value="AAPL USD 500 [20], \nMSFT USD 300 [15], \nGOOGL USD 400 [10], \nAMZN USD 50 [5], \nTSLA USD 200 [10], \nNVDA USD 250 [10], \nNFLX USD 150 [10], \nQQQ USD 450 [5], \nADBE USD 100 [10], \nPYPL USD 50 [5]"
)
title_cash = gr.Markdown("<h3 class='h3_title'>Contribution or withdrawal</h3>")
cash_amount = gr.Number(
    label="Contribution or withdrawal amount",
    value=6693188
)
allow_sales = gr.Checkbox(
    value=True,
    label="If checked, the table below will display both buy and sell transactions. If unchecked, only buy transactions will be shown."
)

input = [main_currency, holdings, cash_amount, allow_sales]
output = gr.HTML()
component_rows = [main_currency, holdings, cash_amount, allow_sales]

# Define the update function
def update_output(*args):
    return rebalancing_tool(*args)