{% if not has_licenses %}
    <p>{{ __('You have no licenses yet.') }}</p>
{% else %}
    <div class="woocommerce-licenses">
        {% for item in licenses %}
            <div class="license-card">
                <div class="license-header">
                    <h3>
                        {% if item.product_url %}
                            <a href="{{ esc_url(item.product_url) }}">{{ esc_html(item.product_name) }}</a>
                        {% else %}
                            {{ esc_html(item.product_name) }}
                        {% endif %}
                    </h3>
                    <span class="license-status license-status-{{ esc_attr(item.license.status) }}">
                        {{ esc_html(item.license.status)|capitalize }}
                    </span>
                </div>

                <div class="license-details">
                    <div class="license-key-row">
                        <label>{{ __('License Key:') }}</label>
                        <code class="license-key" data-license-key="{{ esc_attr(item.license.licenseKey) }}">
                            {{ esc_html(item.license.licenseKey) }}
                        </code>
                        <button type="button" class="copy-license-btn" data-license-key="{{ esc_attr(item.license.licenseKey) }}" title="{{ __('Copy to clipboard') }}">
                            <span class="dashicons dashicons-clipboard"></span>
                        </button>
                    </div>

                    <div class="license-info-row">
                        <span class="license-domain-display" data-license-id="{{ item.license.id }}">
                            <strong>{{ __('Domain:') }}</strong>
                            <span class="domain-value">{{ esc_html(item.license.domain) }}</span>
                            {% if item.license.status == 'active' or item.license.status == 'inactive' %}
                                <button type="button" class="wclp-transfer-btn"
                                        data-license-id="{{ item.license.id }}"
                                        data-current-domain="{{ esc_attr(item.license.domain) }}"
                                        title="{{ __('Transfer to new domain') }}">
                                    <span class="dashicons dashicons-randomize"></span>
                                    {{ __('Transfer') }}
                                </button>
                            {% endif %}
                        </span>
                        <span><strong>{{ __('Expires:') }}</strong>
                            {% if item.license.expiresAt %}
                                {{ item.license.expiresAt|date('Y-m-d') }}
                            {% else %}
                                {{ __('Never') }}
                            {% endif %}
                        </span>
                    </div>
                </div>

                {% if item.downloads is defined and item.downloads is not empty %}
                    <div class="license-downloads">
                        <h4>{{ __('Available Downloads') }}</h4>
                        <ul class="download-list">
                            {% for download in item.downloads %}
                                <li class="download-item">
                                    <div class="download-row-file">
                                        <a href="{{ esc_url(download.download_url) }}" class="download-link">
                                            <span class="dashicons dashicons-download"></span>
                                            {{ esc_html(download.filename ?: 'Version ' ~ download.version) }}
                                        </a>
                                    </div>
                                    <div class="download-row-meta">
                                        <span class="download-date">{{ esc_html(download.released_at) }}</span>
                                        {% if download.file_hash %}
                                            <span class="download-hash" title="{{ esc_attr(download.file_hash) }}">
                                                <span class="dashicons dashicons-shield"></span>
                                                <code>{{ download.file_hash[:12] }}...</code>
                                            </span>
                                        {% endif %}
                                    </div>
                                </li>
                            {% endfor %}
                        </ul>
                    </div>
                {% endif %}
            </div>
        {% endfor %}
    </div>

    <!-- Transfer Modal -->
    <div id="wclp-transfer-modal" class="wclp-modal" style="display:none;">
        <div class="wclp-modal-overlay"></div>
        <div class="wclp-modal-content">
            <button type="button" class="wclp-modal-close" aria-label="{{ __('Close') }}">&times;</button>
            <h3>{{ __('Transfer License to New Domain') }}</h3>
            <form id="wclp-transfer-form">
                <input type="hidden" name="license_id" id="transfer-license-id" value="">

                <div class="wclp-form-row">
                    <label>{{ __('Current Domain') }}</label>
                    <p class="wclp-current-domain"><code id="transfer-current-domain"></code></p>
                </div>

                <div class="wclp-form-row">
                    <label for="transfer-new-domain">{{ __('New Domain') }}</label>
                    <input type="text" name="new_domain" id="transfer-new-domain"
                           placeholder="example.com" required
                           pattern="[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)+">
                    <p class="wclp-field-description">{{ __('Enter the new domain without http:// or www.') }}</p>
                </div>

                <div class="wclp-form-row wclp-form-actions">
                    <button type="submit" class="button wclp-btn-primary" id="wclp-transfer-submit">
                        {{ __('Transfer License') }}
                    </button>
                    <button type="button" class="button wclp-modal-cancel">{{ __('Cancel') }}</button>
                </div>

                <div id="wclp-transfer-message" class="wclp-message" style="display:none;"></div>
            </form>
        </div>
    </div>
{% endif %}
