{# Fragment: Opportunities table + empty states + pagination. Rendered by initial page load ({% include %}) and SSE endpoint (patch_elements). Expects: opportunities (list[dict]), pagination (PaginationContext), config, search_query, selected_status #}
{% if opportunities %}
{% set opp_cols = [ ('type', 'Type', 'left'), ('table', 'Object', 'left'), ('severity', 'Impact', 'right'), ('workload', 'Workload', 'left'), ('cost', 'Query Cost', 'right'), ('savings', 'Savings', 'right'), ('occurrence', 'Occurrences', 'right'), ('detected', 'Detected', 'right'), ] %} {% for col_key, col_label, col_align in opp_cols %} {% endfor %} {% for opp in opportunities %} {% endfor %}
{{ col_label }} Solution
{{ opp.type | replace('_', ' ') }} {{ opp.dbt_model if opp.dbt_model != '—' else opp.table_short }}
{% if opp.severity_score >= 70 %}High{% elif opp.severity_score >= 40 %}Medium{% else %}Low{% endif %}
{% if opp.query_workload_kind == 'build' %} Build {% elif opp.query_workload_kind == 'consumption' %} Consumption {% elif local_execution_mode %} Unclassified {% else %} Other {% endif %} {% if opp.query_cost_value is not none %}
{{ opp.query_cost_value | format_usd }} {{ opp.query_cost_source_label }}
{% else %} {% endif %}
{% if opp.optimized_cost_value is not none %}
{{ opp.optimized_cost_value | format_usd }} {% if opp.optimized_delta_direction == 'down' %} {% elif opp.optimized_delta_direction == 'up' %} {% endif %}
{{ opp.optimized_cost_source_label }}
{% elif opp.solution_job_status in ('queued', 'in_progress') %}
Generating Solution {{ 'running' if opp.solution_job_status == 'in_progress' else 'queued' }}
{% elif opp.solution_job_status == 'failed' %}
Failed Click to retry
{% elif opp.possible_savings_value is not none %}
~{{ opp.possible_savings_value | format_usd }}
{{ opp.possible_savings_label }}
{% else %} {% endif %}
{{ opp.occurrence_count }} {{ opp.created_at }} {% if opp.solution_risk_level == 'low' %} Safe {% elif opp.solution_risk_level == 'medium' %} Review {% elif opp.solution_risk_level == 'high' %} High risk {% elif opp.solution_job_status in ('queued', 'in_progress') %} {{ 'Running' if opp.solution_job_status == 'in_progress' else 'Queued' }} {% else %} Pending {% endif %}
{% include "project/_opportunities_pagination.html" %} {% else %}
{% if search_query %}

No opportunities match your filter.

{% elif selected_status == 'active' and background_jobs_running %}

Analysis in progress — opportunities and savings are still being updated.

{% elif selected_status == 'active' %}

No active opportunities detected.

{% else %}

No {{ selected_status }} opportunities found.

{% endif %}
{% endif %}