module.exports = [
"[externals]/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-route-turbo.runtime.dev.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js"));

module.exports = mod;
}),
"[externals]/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-page-turbo.runtime.dev.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js"));

module.exports = mod;
}),
"[externals]/next/dist/server/app-render/work-unit-async-storage.external.js [external] (next/dist/server/app-render/work-unit-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/server/app-render/work-unit-async-storage.external.js", () => require("next/dist/server/app-render/work-unit-async-storage.external.js"));

module.exports = mod;
}),
"[externals]/next/dist/server/app-render/work-async-storage.external.js [external] (next/dist/server/app-render/work-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/server/app-render/work-async-storage.external.js", () => require("next/dist/server/app-render/work-async-storage.external.js"));

module.exports = mod;
}),
"[externals]/next/dist/shared/lib/no-fallback-error.external.js [external] (next/dist/shared/lib/no-fallback-error.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/shared/lib/no-fallback-error.external.js", () => require("next/dist/shared/lib/no-fallback-error.external.js"));

module.exports = mod;
}),
"[externals]/next/dist/server/app-render/after-task-async-storage.external.js [external] (next/dist/server/app-render/after-task-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/server/app-render/after-task-async-storage.external.js", () => require("next/dist/server/app-render/after-task-async-storage.external.js"));

module.exports = mod;
}),
"[externals]/mongoose [external] (mongoose, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("mongoose", () => require("mongoose"));

module.exports = mod;
}),
"[project]/Desktop/Aynnaka/DiffaTours-main 2/src/lib/mongodb.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "connectDB",
    ()=>connectDB,
    "default",
    ()=>__TURBOPACK__default__export__
]);
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
;
let cached = global.mongoose || {
    conn: null,
    promise: null
};
if (!global.mongoose) {
    global.mongoose = cached;
}
const MONGODB_URI = process.env.MONGODB_URI;
if (!MONGODB_URI) {
    throw new Error('Missing MONGODB_URI environment variable');
}
async function connectDB() {
    // Return existing connection if ready
    if (cached.conn?.connection.readyState === 1) {
        return cached.conn;
    }
    // Wait for pending connection
    if (cached.promise) {
        cached.conn = await cached.promise;
        return cached.conn;
    }
    // Create new connection with serverless-optimized settings
    // MONGODB_URI is guaranteed to be string here due to the check above
    cached.promise = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].connect(MONGODB_URI, {
        bufferCommands: false,
        maxPoolSize: 1,
        minPoolSize: 0,
        serverSelectionTimeoutMS: 5000,
        socketTimeoutMS: 30000,
        heartbeatFrequencyMS: 10000,
        maxIdleTimeMS: 10000,
        waitQueueTimeoutMS: 5000
    });
    try {
        cached.conn = await cached.promise;
        console.log('MongoDB connected');
        return cached.conn;
    } catch (error) {
        cached.promise = null;
        console.error('MongoDB connection error:', error);
        throw error;
    }
}
const __TURBOPACK__default__export__ = connectDB;
}),
"[project]/Desktop/Aynnaka/DiffaTours-main 2/src/models/ExcursionCapacity.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "default",
    ()=>__TURBOPACK__default__export__
]);
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
;
const ExcursionCapacitySchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    excursionId: {
        type: String,
        required: true,
        index: true
    },
    date: {
        type: String,
        required: true,
        index: true
    },
    maxCapacity: {
        type: Number,
        required: true
    },
    currentBookings: {
        type: Number,
        required: true,
        default: 0
    },
    isAvailable: {
        type: Boolean,
        required: true,
        default: true
    },
    createdAt: {
        type: Date,
        default: Date.now
    },
    updatedAt: {
        type: Date,
        default: Date.now
    }
}, {
    collection: 'excursioncapacities'
});
// Compound index for unique excursion-date pairs
ExcursionCapacitySchema.index({
    excursionId: 1,
    date: 1
}, {
    unique: true
});
const __TURBOPACK__default__export__ = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.ExcursionCapacity || __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].model('ExcursionCapacity', ExcursionCapacitySchema);
}),
"[project]/Desktop/Aynnaka/DiffaTours-main 2/src/app/api/capacity/calendar/[excursion_id]/route.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "GET",
    ()=>GET
]);
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Desktop/Aynnaka/DiffaTours-main 2/node_modules/next/server.js [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$src$2f$lib$2f$mongodb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Desktop/Aynnaka/DiffaTours-main 2/src/lib/mongodb.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$src$2f$models$2f$ExcursionCapacity$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Desktop/Aynnaka/DiffaTours-main 2/src/models/ExcursionCapacity.ts [app-route] (ecmascript)");
;
;
;
async function GET(request, { params }) {
    try {
        await (0, __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$src$2f$lib$2f$mongodb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["connectDB"])();
        const { excursion_id } = await params;
        // Validate excursion_id
        if (!excursion_id || typeof excursion_id !== 'string' || excursion_id.trim() === '') {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'Valid excursion_id is required',
                code: 'INVALID_EXCURSION_ID'
            }, {
                status: 400
            });
        }
        // Parse query parameters
        const { searchParams } = new URL(request.url);
        const monthParam = searchParams.get('month');
        const yearParam = searchParams.get('year');
        // Validate month parameter
        if (!monthParam) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'Month parameter is required',
                code: 'MISSING_MONTH'
            }, {
                status: 400
            });
        }
        const month = parseInt(monthParam);
        if (isNaN(month) || month < 1 || month > 12) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'Month must be a number between 1 and 12',
                code: 'INVALID_MONTH'
            }, {
                status: 400
            });
        }
        // Validate year parameter
        if (!yearParam) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'Year parameter is required',
                code: 'MISSING_YEAR'
            }, {
                status: 400
            });
        }
        const year = parseInt(yearParam);
        if (isNaN(year) || year < 1000 || year > 9999) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'Year must be a valid 4-digit number',
                code: 'INVALID_YEAR'
            }, {
                status: 400
            });
        }
        // Calculate start_date and end_date for the month
        const startDate = `${year}-${String(month).padStart(2, '0')}-01`;
        const lastDay = new Date(year, month, 0).getDate();
        const endDate = `${year}-${String(month).padStart(2, '0')}-${String(lastDay).padStart(2, '0')}`;
        // Query excursionCapacity collection
        const capacityRecords = await __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$src$2f$models$2f$ExcursionCapacity$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].find({
            excursionId: excursion_id,
            date: {
                $gte: startDate,
                $lte: endDate
            }
        }).sort({
            date: 1
        });
        console.log(`Checking capacity for ${excursion_id} from ${startDate} to ${endDate}`);
        console.log(`Found ${capacityRecords.length} capacity records`);
        // Create a map for quick lookup of capacity records by date
        const capacityMap = new Map(capacityRecords.map((record)=>[
                record.date,
                record
            ]));
        // Generate complete calendar array for all days in month
        const calendar = [];
        for(let day = 1; day <= lastDay; day++){
            const dateString = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
            const capacityRecord = capacityMap.get(dateString);
            if (capacityRecord) {
                // Day has capacity record
                const availableSpots = capacityRecord.maxCapacity - capacityRecord.currentBookings;
                let availabilityStatus;
                if (availableSpots <= 0) {
                    availabilityStatus = 'full';
                } else if (availableSpots < capacityRecord.maxCapacity * 0.2) {
                    availabilityStatus = 'limited';
                } else {
                    availabilityStatus = 'available';
                }
                calendar.push({
                    date: dateString,
                    hasCapacityLimit: true,
                    maxCapacity: capacityRecord.maxCapacity,
                    currentBookings: capacityRecord.currentBookings,
                    availableSpots,
                    isAvailable: capacityRecord.isAvailable,
                    availabilityStatus
                });
            } else {
                // Day without capacity record (unlimited)
                calendar.push({
                    date: dateString,
                    hasCapacityLimit: false,
                    availabilityStatus: 'available',
                    message: 'No capacity limit'
                });
            }
        }
        // Return calendar data
        return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            excursionId: excursion_id,
            month,
            year,
            calendar,
            totalDays: lastDay
        }, {
            status: 200
        });
    } catch (error) {
        console.error('GET calendar error:', error);
        return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            error: 'Internal server error: ' + (error instanceof Error ? error.message : 'Unknown error')
        }, {
            status: 500
        });
    }
}
}),
];

//# sourceMappingURL=%5Broot-of-the-server%5D__b6a4153c._.js.map