import { KOMI_USER_LOCATION, authInternalTracker, authTracking } from '../shared';
import { getPlatform, track } from '../tracking';
import { getUTMParams } from '../utils/utm';
import Cookies from 'js-cookie';
import platform from 'platform';
export class AuthTrackerBuilder {
}
AuthTrackerBuilder.create = (event, ...trackingArgs) => {
    const { group, fn } = authTracking[event];
    return (...trackerArgs) => {
        var _a;
        let trackerProps = void 0;
        let options;
        const trackingProps = group instanceof Function
            ?
                group(...trackingArgs)
            : void 0;
        if (!fn || !fn.length) {
            options = trackerArgs[0];
        }
        else {
            trackerProps = fn(trackerArgs[0]);
            options = trackerArgs[1];
        }
        const utmParams = getUTMParams();
        const internalProps = authInternalTracker(Object.assign({ height: (window === null || window === void 0 ? void 0 : window.innerHeight) || 0, location: Cookies.get(KOMI_USER_LOCATION), os: (_a = platform.os) === null || _a === void 0 ? void 0 : _a.toString(), platform: getPlatform(), referrer: document.referrer, width: (window === null || window === void 0 ? void 0 : window.innerWidth) || 0 }, utmParams));
        const data = Object.assign(Object.assign(Object.assign({}, internalProps), trackingProps), trackerProps);
        track(event, data, options);
    };
};
export default AuthTrackerBuilder;
export const { create: createAuthTracker } = AuthTrackerBuilder;
