<!-- 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: 110px;
        text-align: center;
        transition: transform 0.3s ease;
        border-radius: 10px;
        background: linear-gradient(145deg, #f0f0f0, #cacaca);
        box-shadow: 5px 5px 10px #bebebe, -5px -5px 10px #ffffff;
        cursor: pointer;
        overflow: visible;
    }

    .backtest-item:hover {
        transform: translateY(-3px);
        box-shadow: 8px 8px 15px #bebebe, -8px -8px 15px #ffffff;
    }

    /* Backtest icon area */
    .backtest-icon {
        width: 100%;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        margin-top: 5px;
    }

    .backtest-icon::before {
        content: '';
        width: 40px;
        height: 40px;
        border-radius: 8px;
        position: absolute;
    }

    .backtest-icon .backtest-symbol {
        position: relative;
        z-index: 1;
        font-size: 24px;
    }

    /* Status-based icon backgrounds */
    .backtest-item.default .backtest-icon::before,
    .backtest-item.running .backtest-icon::before {
        background: linear-gradient(135deg, #f7b733 0%, #fc4a1a 100%);
    }

    .backtest-item.complete .backtest-icon::before {
        background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    }

    .backtest-item.error .backtest-icon::before {
        background: linear-gradient(135deg, #cb2d3e 0%, #ef473a 100%);
    }

    /* Status borders */
    .backtest-item.running {
        border: 3px solid #ffa500;
        animation: pulse-orange 2s infinite;
    }

    .backtest-item.complete {
        border: 3px solid #28a745;
    }

    .backtest-item.error {
        border: 3px solid #dc3545;
    }

    @keyframes pulse-orange {
        0% { box-shadow: 0 0 0 0 rgba(255, 165, 0, 0.4); }
        70% { box-shadow: 0 0 0 10px rgba(255, 165, 0, 0); }
        100% { box-shadow: 0 0 0 0 rgba(255, 165, 0, 0); }
    }

    .backtest-name {
        font-size: 11px;
        font-weight: bold;
        text-align: center;
        color: #333;
        padding: 2px 5px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 94px;
        margin: 0 auto;
    }

    .backtest-status {
        font-size: 9px;
        text-align: center;
        color: #888;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .backtest-date {
        font-size: 10px;
        text-align: center;
        color: #666;
        padding: 2px 5px;
    }

    .backtest-item .delete-button {
        position: absolute;
        top: -8px;
        right: -8px;
        width: 22px;
        height: 22px;
        border-radius: 50%;
        background: #dc3545;
        color: white;
        border: 2px solid white;
        font-size: 14px;
        font-weight: bold;
        cursor: pointer;
        display: none;
        align-items: center;
        justify-content: center;
        z-index: 10;
        line-height: 1;
    }

    .backtest-item:hover .delete-button {
        display: flex;
    }

    .backtest-item .delete-button:hover {
        transform: scale(1.2);
    }
    #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>

