import axios from 'axios';
import { Cookies } from 'react-cookie';
import Router from 'next/router';
import moment from 'moment';
import { nSQL } from "@nano-sql/core";
import { eachSeries } from 'async';

import * as actionTypes from '../constants/actionTypes';
import * as currentState from '../reducers/initialState';

export const logDocumentAccess = (payload) => 
{
	const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/logs/track`;

	console.log("ACTION", "deals", "logDocumentAccess()", { url });
	console.log("ACTION", "deals", "logDocumentAccess()", { payload });

	return new Promise((resolve, reject) => 
	{
		payload.lk_user_id = global.store.getState().user.email;
		payload.acc_number = global.store.getState().company.active;

		axios.post(url, [ payload ], {
			withCredentials: true, 
		})
		.then((response) => 
		{
			console.log("ACTION", "deals", "logDocumentAccess()", "response", response.data);

			resolve();
		})
		.catch((error) => 
		{
			console.error("ACTION", "deals", "logDocumentAccess()", "ERROR");
			console.error(error);

			reject();
		});	
	});
}