<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Legal Notices</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 900px;
            margin: 0 auto;
            padding: 20px;
            background: #f5f5f5;
        }
        h1 {
            color: #2c3e50;
            border-bottom: 3px solid #3498db;
            padding-bottom: 10px;
        }
        h2 {
            color: #34495e;
            margin-top: 30px;
            border-bottom: 1px solid #bdc3c7;
            padding-bottom: 5px;
        }
        .package-list {
            background: white;
            padding: 15px;
            border-radius: 5px;
            margin: 10px 0;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .package-item {
            padding: 5px 0;
            border-bottom: 1px solid #ecf0f1;
        }
        .package-item:last-child {
            border-bottom: none;
        }
        .copyright-section {
            background: #ecf0f1;
            padding: 10px;
            border-radius: 3px;
            margin: 10px 0;
        }
        .license-text {
            background: white;
            padding: 15px;
            border-left: 4px solid #3498db;
            margin: 10px 0;
            white-space: pre-wrap;
            font-family: "Courier New", Courier, monospace;
            font-size: 0.9em;
            overflow-x: auto;
        }
        .license-badge {
            display: inline-block;
            background: #3498db;
            color: white;
            padding: 3px 8px;
            border-radius: 3px;
            font-size: 0.85em;
            margin-right: 5px;
        }
        .no-license {
            background: #e74c3c;
        }
        html {
            scroll-behavior: smooth;
        }
    </style>
</head>
<body>
    <h1>Legal Notices</h1>
    <p>This product includes software developed by third parties. The following notices apply to the included packages:</p>

    <!-- Table of Contents -->
    <div style="background: white; padding: 20px; border-radius: 5px; margin: 20px 0; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
        <h2 style="color: #2c3e50; margin-top: 0;">Table of Contents</h2>
        <ul style="list-style: none; padding-left: 0;">
            {% if group_by_license %}
            {% for license_id, package_group in packages_by_license.items() %}
            {% for package in package_group %}
            <li style="margin: 8px 0;">
                <a href="#package-{{ package.name | replace(' ', '-') | replace('@', '') | replace('/', '-') | replace(':', '-') | lower }}-{{ package.version | replace('.', '-') | replace(':', '-') }}"
                   style="text-decoration: none; color: #3498db;">
                    {{ package.display_name }}
                    <span style="color: #7f8c8d; font-size: 0.9em;">({{ license_id }})</span>
                </a>
            </li>
            {% endfor %}
            {% endfor %}
            {% else %}
            {% for package in packages %}
            <li style="margin: 8px 0;">
                <a href="#package-{{ package.name | replace(' ', '-') | replace('@', '') | replace('/', '-') | replace(':', '-') | lower }}-{{ package.version | replace('.', '-') | replace(':', '-') }}"
                   style="text-decoration: none; color: #3498db;">
                    {{ package.display_name }}
                    {% if package.licenses %}
                    <span style="color: #7f8c8d; font-size: 0.9em;">({{ package.licenses | map(attribute='spdx_id') | join(', ') }})</span>
                    {% endif %}
                </a>
            </li>
            {% endfor %}
            {% endif %}
        </ul>
    </div>

    {% if group_by_license %}
    {% for license_id, package_group in packages_by_license.items() %}
    <h2>
        <span class="license-badge{% if license_id == 'NOASSERTION' %} no-license{% endif %}">{{ license_id }}</span>
    </h2>

    <div class="package-list">
        <h3>Packages:</h3>
        {% for package in package_group %}
        <div class="package-item" id="package-{{ package.name | replace(' ', '-') | replace('@', '') | replace('/', '-') | replace(':', '-') | lower }}-{{ package.version | replace('.', '-') | replace(':', '-') }}">{{ package.display_name }}</div>
        {% endfor %}
    </div>

    {% if include_copyright %}
    <div class="copyright-section">
        <h3>Copyright Notices:</h3>
        {% for package in package_group %}
        {% for copyright in package.copyrights %}
        <div>{{ copyright.statement }}</div>
        {% endfor %}
        {% endfor %}
    </div>
    {% endif %}

    {% if include_license_text %}
    <h3>License Text:</h3>
    <div class="license-text">{{ license_texts.get(license_id, 'License text not available') }}</div>
    {% endif %}
    {% endfor %}
    
    {% else %}
    {% for package in packages %}
    <h2 id="package-{{ package.name | replace(' ', '-') | replace('@', '') | replace('/', '-') | replace(':', '-') | lower }}-{{ package.version | replace('.', '-') | replace(':', '-') }}">{{ package.display_name }}</h2>
    
    <div class="package-list">
        <strong>License:</strong>
        {% if package.license_ids %}
        {% for license_id in package.license_ids %}
        <span class="license-badge">{{ license_id }}</span>
        {% endfor %}
        {% else %}
        <span class="license-badge no-license">NOASSERTION</span>
        {% endif %}
    </div>

    {% if include_copyright and package.copyrights %}
    <div class="copyright-section">
        <h3>Copyright Notices:</h3>
        {% for copyright in package.copyrights %}
        <div>{{ copyright.statement }}</div>
        {% endfor %}
    </div>
    {% endif %}

    {% if include_license_text %}
    {% for license in package.licenses %}
    <h3>{{ license.spdx_id }} License Text:</h3>
    <div class="license-text">{{ license.text if license.text else 'License text not available' }}</div>
    {% endfor %}
    {% endif %}
    {% endfor %}
    {% endif %}

    <!-- Back to top link -->
    <div style="text-align: center; margin: 40px 0;">
        <a href="#" style="color: #3498db; text-decoration: none;">↑ Back to Top</a>
    </div>

    <hr style="margin-top: 50px; border: 1px solid #bdc3c7;">
    <p style="text-align: center; color: #7f8c8d; font-size: 0.9em;">
        End of Legal Notices - Generated by purl2notices
    </p>
</body>
</html>