var utils = require("./lib/utils")

;(function () {
    const col = context.collection()
    const collectionName = col && col.name ? col.name : null
    const req = context.request()
    const method = req.method
    const data = /** @type {Record<string, any>} */ (Array.isArray(context.data) ? {} : context.data || {})
    let entryId = data.id || req.param("id") || null

    // DELETE hooks may not populate context.data.id or route params consistently.
    if (!entryId) {
        const path = req.path
        const segments = path.split("/")
        const last = segments[segments.length - 1]
        if (last && last.length >= 24) {
            entryId = last
        }
    }

    utils.clearSSRCache(collectionName, entryId, method)
})()
