<!-- Backtest Form Popup -->
<div class="form-popup" id="backtest_form" style="display: none; overflow: hidden; position: absolute; width: 400px; height: 600px; border-radius: 10px;">

    <!-- Draggable Header Section -->
    <div class="dialog-header" id="backtest_draggable_header">
        <h1 id="backtest-form-header">Create New Backtest</h1>
        <button class="dialog-close-btn" onclick="UI.backtesting.closeForm()">&times;</button>
    </div>

    <!-- Main Content (Scrollable) -->
    <form class="form-container" style="overflow-y: auto;">
        <!-- Select Strategy -->
        <div>
            <label for="strategy_select" style="display: inline-block; width: 30%;">Strategy:</label>
            <select id="strategy_select" name="strategy_select" style="width: 65%;"></select>
        </div>

        <!-- Start Date -->
        <div>
            <label for="start_date" style="display: inline-block; width: 30%;">Start Date/Time:</label>
            <input type="datetime-local" id="start_date" name="start_date" style="width: 65%;" required>
        </div>

        <!-- Initial Capital -->
        <div>
            <label for="initial_capital" style="display: inline-block; width: 30%;">Initial Capital:</label>
            <input type="number" id="initial_capital" name="initial_capital" style="width: 65%;" required value="10000">
        </div>

        <!-- Commission -->
        <div>
            <label for="commission" style="display: inline-block; width: 30%;">Commission:</label>
            <input type="number" step="0.0001" id="commission" name="commission" style="width: 65%;" required value="0.001">
        </div>

        <!-- Buttons -->
        <div style="text-align: center;">
            <button type="button" class="btn cancel" onclick="UI.backtesting.closeForm()">Close</button>
            <button id="backtest-submit-create" type="button" class="btn next" onclick="UI.backtesting.submitTest()">Run Test</button>
            <button id="backtest-submit-edit" type="button" class="btn next" onclick="UI.backtesting.submitTest()" style="display:none;">Edit Test</button>
        </div>

        <!-- Status message (Initially Hidden) -->
        <div id="backtest-status-message" style="margin-top: 10px; color: blue;"></div>

        <!-- Progress bar (Initially Hidden) -->
        <div id="backtest-progress-container">
            <div id="progress_bar" style="width: 0%; height: 20px; background-color: green; text-align: center; color: white;">
                0%
            </div>
        </div>

        <!-- Results section (Initially Hidden) -->
        <div id="backtest-results">
            <h4>Test Results</h4>
            <pre id="results_display"></pre>
        </div>
    </form>

    <!-- Resizer -->
    <div id="resize-backtest" class="resize-handle"></div>
</div>

<style>
    /* Styling for backtest popup and container */
    .backtests-container {
        display: flex;
        flex-wrap: wrap;
        gap: 20px;
    }

    .backtest-item {
        position: relative;
        width: 100px;
        height: 100px;
        text-align: center;
        transition: transform 0.3s ease;
        background-size: cover; /* Ensure the background image covers the entire div */
        background-position: center; /* Center the image */
        border: 1px solid #ccc; /* Optional: Add a border for better visibility */
        border-radius: 8px; /* Optional: Rounded corners */
    }

    .backtest-item:hover {
        transform: scale(1.05);
    }
    /* Add a default background image */
    .backtest-item.default {
        background-image: url('/static/test_running_icon.webp');
    }

    /* Add background for specific statuses if needed */
    .backtest-item.running {
        background-image: url('/static/test_running_icon.webp');
        background-color: #f3f981; /* Highlight running tests with a yellow background */
        border-color: #ffa500;    /* Add an orange border for emphasis */
    }

    .backtest-item.complete {
        background-image: url('/static/test_complete_icon.webp');
        background-color: #d4edda; /* Green for completed tests */
        border-color: #28a745;
    }

    .backtest-item.error {
        background-color: #f8d7da; /* Red for tests with errors */
        border-color: #dc3545;
    }

    .backtest-name {
        position: absolute;
        top: 80px;
        left: 50%;
        transform: translateX(-50%);
        background-color: white;
        padding: 5px;
        border-radius: 10px;
        color: black;
        text-align: center;
        width: 100px;
        font-size: 12px;
    }

    .delete-button {
        position: absolute;
        top: 5px;
        left: 5px;
        background-color: red;
        color: white;
        border-radius: 50%;
        width: 20px;
        height: 20px;
    }
    #backtest-progress-container {
        display: none; /* Initially hidden */
        margin-top: 10px;
    }

    #backtest-progress-container.show {
        display: block; /* Show when backtest is running */
    }
    #results_display {
        margin-top: 10px;
    }

    #results_display table {
        width: 100%;
        border-collapse: collapse;
    }

    #results_display th, #results_display td {
        border: 1px solid #ccc;
        padding: 5px;
        text-align: center;
    }

    #results_display th {
        background-color: #f2f2f2;
    }
    #backtest-results {
        margin-top: 10px;
        display: none; /* Initially hidden */
    }
    #backtest-results.show {
        display: block; /* Show when backtest is complete */
    }
    #backtest-status-message {
        display: none;
    }
    #backtest-status-message.show{
        display: block;
    }
</style>

