// @ts-nocheck
import { useEffect } from 'react';

export const SPOTIFY_PIXEL_ID = '5f20186e95ea4dedbbf28d04540cfabf';

export function useSpotifyPixel(pixelId: string) {
  return (event: string) =>
    setTimeout(() => {
      if (process.env.NODE_ENV === 'development') {
        console.log('Would track on Spotify:', event);
        return;
      }

      (function (w, d) {
        var id = 'spdt-capture',
          n = 'script';
        if (!d.getElementById(id)) {
          w.spdt =
            w.spdt ||
            function () {
              (w.spdt.q = w.spdt.q || []).push(arguments);
            };
          var e = d.createElement(n);
          e.id = id;
          e.async = 1;
          e.src = 'https://pixel.byspotify.com/ping.min.js';
          var s = d.getElementsByTagName(n)[0];
          s.parentNode.insertBefore(e, s);
        }
        w.spdt('conf', { key: pixelId });
        w.spdt(event);
      })(window, document);
    });
}
