<!-- templates/order_results.html -->
<link href="{{ url_for('static', path='ship.css') }}" rel="stylesheet">
{% block head %}
    <script src="{{ url_for('static', path='ship.js') }}"></script>
    <link href="{{ url_for('static', path='ship.css') }}" rel="stylesheet">
{% endblock %}
{% if alerts %}
    {% include "alerts.html" with context %}
{% endif %}
<div class="wrapper wrapper__results">
    {% if response.success %}
        <div class="result result__success">
            <h2>Shipment Confirmed</h2>
            <h3>Shipment Number: {{ response.shipment_num }}</h3>

            <p>label downloaded to {{ response.label_path }}</p>
            <div id="label-action-result"></div>
            <div class="label-actions">
                <div class="label-action">
                    <form hx-get="{{ request.url_for('print_file', filepath=response.label_path | urlencode) }}"
                          hx-target="#print-btn"
                          hx-swap="afterbegin"
                    >
                        <button type="submit" id="print-btn" class="btn-print-label">Print Label</button>
                    </form>
                </div>

                <div class="label-action">
                    <script>console.log("OPEN FILE{{ response.label_path }}")</script>
                    <form hx-get="{{ request.url_for('open_file', filepath = response.label_path| urlencode ) }}"
                          hx-target="#open-btn"
                          hx-swap="afterbegin">
                        <button type="submit" id="open-btn" class="btn-print-label">Open Label</button>
                    </form>
                </div>

                <div class="label-action">
                    <script>console.log("Email Label {{ response.label_path }}")</script>
                    <form hx-post="{{ request.url_for("email_label") }}"
                          hx-target="#email-btn"
                          hx-swap="afterbegin">
                        <input type="hidden" name="label_path" value="{{ response.label_path | urlencode }}">
                        <input type="hidden" name="shipment_request_json"
                               value="{{ shipment_request.model_dump_json() }}">
                        <button type="submit" id="email-btn" class="btn-print-label">Email Label</button>


                    </form>
                </div>
            </div>
        </div>
    {% else %}
        <div class="result result__failure">
            <h2>Booking Failed</h2>
            <p>There was a problem with your booking.</p>
        </div>
    {% endif %}

</div>
