(async () => {
    const apiClient = window.ApiClient;
    if (!apiClient) {
        console.error("ApiClient not found. Are you logged in?");
        return;
    }

    const userId = apiClient.getCurrentUserId();
    const serverAddress = apiClient.serverAddress();

    const maxDaysRecent = 30; // Test: Added in last 30 days
    const pastDate = new Date();
    pastDate.setDate(pastDate.getDate() - maxDaysRecent);
    const dateStr = pastDate.toISOString();

    console.log(`Searching for items added after: ${dateStr}`);

    const testUrls = [
        // Test 1: minDateCreated (CamelCase)
        `${serverAddress}/Items?IncludeItemTypes=Movie,Series&Recursive=true&enableUserData=true&Limit=5&fields=Id,DateCreated&userId=${userId}&minDateCreated=${dateStr}`,
        // Test 2: minDateLastSaved
        `${serverAddress}/Items?IncludeItemTypes=Movie,Series&Recursive=true&enableUserData=true&Limit=5&fields=Id,DateCreated&userId=${userId}&minDateLastSaved=${dateStr}`,
    ];

    try {
        for (let i = 0; i < testUrls.length; i++) {
            const apiUrl = testUrls[i];
            console.log(`\n%cTest ${i+1}: Testing URL:\n${apiUrl}`, "color: yellow;");

            const response = await fetch(apiUrl, {
                headers: {
                    Authorization: `MediaBrowser Client="${apiClient.appName()}", Device="${apiClient.deviceName()}", DeviceId="${apiClient.deviceId()}", Version="${apiClient.appVersion()}", Token="${apiClient.accessToken()}"`
                }
            });

            if (!response.ok) {
                 console.error(`Failed to fetch items: ${response.status} ${response.statusText}`);
                 continue;
            }

            const data = await response.json();
            const items = data.Items || [];

            console.log(`%cErgebnis: ${items.length} Items gefunden!`, "color: #00a4dc; font-weight: bold;");
            
            if(items.length > 0) {
                console.log("Gefundene Items:");
                items.forEach(item => {
                    console.log(`- Name: ${item.Name}, DateCreated: ${item.DateCreated}, Art: ${item.Type}`);
                });
            }
        }
    } catch (error) {
        console.error("Fehler beim Abrufen der URL:", error);
    }
})();
