{"version":3,"file":"Counter-BB_xrodQ.js","sources":["../../../../../front/src/js/Counter.ts"],"sourcesContent":["export class Counter {\n    private postId: number;\n    private readonly COOKIE_PREFIX = 'rr_view_';\n\n    constructor() {\n        this.postId = +(document.body.dataset.postId ?? -1);\n    }\n\n    private hasCookie(postId: number): boolean {\n        return document.cookie.split(';')\n            .some(cookie => cookie.trim().startsWith(`${this.COOKIE_PREFIX}${postId}=`));\n    }\n\n    async incrementPostViews(): Promise<void> {\n        if (this.postId === -1 || this.hasCookie(this.postId)) {\n            return;\n        }\n\n        try {\n            const response = await fetch(`${wpApiSettings.root}rr/v2/post-views/${this.postId}`, {\n                method: 'POST',\n                credentials: 'same-origin',\n                headers: {\n                    'Content-Type': 'application/json',\n                    // 'X-WP-Nonce': wpApiSettings.nonce\n                }\n            });\n    \n            if (!response.ok) {\n                throw new Error('Failed to increment post views');\n            }\n        } catch (error) {\n            console.error('Error incrementing post views:', error);\n        }\n    }\n}"],"names":["Counter","__publicField","postId","cookie","error"],"mappings":"oKAAO,MAAMA,CAAQ,CAIjB,aAAc,CAHNC,EAAA,eACSA,EAAA,qBAAgB,YAG7B,KAAK,OAAS,EAAE,SAAS,KAAK,QAAQ,QAAU,GAAA,CAG5C,UAAUC,EAAyB,CACvC,OAAO,SAAS,OAAO,MAAM,GAAG,EAC3B,KAAeC,GAAAA,EAAO,KAAK,EAAE,WAAW,GAAG,KAAK,aAAa,GAAGD,CAAM,GAAG,CAAC,CAAA,CAGnF,MAAM,oBAAoC,CACtC,GAAI,OAAK,SAAW,IAAM,KAAK,UAAU,KAAK,MAAM,GAIhD,GAAA,CAUI,GAAA,EATa,MAAM,MAAM,GAAG,cAAc,IAAI,oBAAoB,KAAK,MAAM,GAAI,CACjF,OAAQ,OACR,YAAa,cACb,QAAS,CACL,eAAgB,kBAAA,CAEpB,CACH,GAEa,GACJ,MAAA,IAAI,MAAM,gCAAgC,QAE/CE,EAAO,CACJ,QAAA,MAAM,iCAAkCA,CAAK,CAAA,CACzD,CAER"}