import Cookies from 'js-cookie'
import state from "./state";

export const setCookie = (key,value) =>{
    Cookies.set(key, value);
}
export const getCookie = (key) =>{
    return Cookies.get(key);
}
export const unsetCookie = (key) =>{
    return Cookies.remove(key);
}
export const setLocalStorage = (key,value) =>{
    localStorage.setItem(key, value);
}
export const getLocalStorage = (key) =>{
    return localStorage.getItem(key);
}
export const unsetLocalStorage = (key) =>{
    return localStorage.removeItem(key);
}


export const getAmount = ()=> {
    return Cookies.get('amount');
}

export const setAmount = (amount)=> {
    Cookies.set('amount', amount);
}

export const getSecurityKey = ()=> {
    return getCookie('security_key'); //Cookies.get('security_key');
}

export const setSecurityKey = (key)=> {
    setCookie('security_key',key);
    //Cookies.set('security_key', key);
}

export const setPackageId = (package_id) => {
    Cookies.set('package_id', package_id);
}

export const getPackageId = () => {
  //return Cookies.get('package_id');
    return 2;
}

export const setStep = (step) => {
    Cookies.set('step', step);
}

export const getStep = () => {
    return Cookies.get('step');
}

export const setToken = (token) => {
    Cookies.set('access_token', token);
}

export const unsetStep = () => {
    Cookies.remove('step');
}

export const setUserId = (user_id) => {
    Cookies.set('user_id', user_id);
}

export const setUserEmail = (email) => {
    Cookies.set('user_email', email);
}

export const getUserId = () => {
    return Cookies.get('user_id');
}

export const getUserEmail = () => {
    return Cookies.get('user_email');
}


export const setRefreshToken = (token) => {
    Cookies.set('refresh_token', token);
}

export const getToken = () => {
    return Cookies.get('access_token');
}

export const getRefreshToken = () => {
    return Cookies.get('refresh_token');
}

export const removeToken = () => {
    Cookies.remove('access_token');
    Cookies.remove('refresh_token');
}

export const isApiSuccess = (response) => {
    return response.statuscode == 100;
}
export const setUserFirstName = (name) => {
    Cookies.set('user_first_name', name);
}
export const setUserLastName = (name) => {
    Cookies.set('user_last_name', name);
}
export const setUserPassword = (password) => {
    Cookies.set('user_password', password);
}
export const setFormData = (form_data) => {
    setCookie('user_input_data',form_data)
}
export const getFormData = () => {
   return getCookie('user_input_data');
}
export const unsetFormData = () => {
    unsetCookie('user_input_data');
}
export const setUserQuestionAnswer = (data) => {
    setCookie('user_answer_data',data)
}
export const getUserQuestionAnswer = () => {
    return getCookie('user_answer_data');
}
export const unsetUserQuestionAnswer = () => {
    unsetCookie('user_answer_data');
}

export const setCardNumber = (cardNumber) => {
    Cookies.set('card_number', cardNumber);
}
export const setExpiry = (expiry) => {
    Cookies.set('expiry', expiry);
}
export const setFullSsn = (expiry) => {
    Cookies.set('full_ssn', expiry);
}
export const setPhone = (phone) => {
    Cookies.set('phone',phone);
}
export const setZip_Code = (zip_code) => {
    Cookies.set('zip_code',zip_code);
}
export const setStreetNo=(data)=>{
    Cookies.set('street_no',data);
}
export const setStreetName=(data)=>{
    Cookies.set('street_name',data);
}
export const setCity=(data)=>{
    Cookies.set('city',data);
}
export const setState=(data)=>{
    Cookies.set('state',data);
}
export const setBirthDate=(data)=>{
    Cookies.set('birth_date',data);
}
export const setQuestionId=(data)=>{
    Cookies.set('question_id',data);
}
export const setAnswer=(data)=>{
    Cookies.set('answer',data);
}

export const getFullSsn = () => {
    return Cookies.get('full_ssn');
}
export const getUserFirstName = () => {
    return Cookies.get('user_first_name');
}
export const getUserLastName = () => {
    return Cookies.get('user_last_name');
}
export const getUserPassword = () => {
    return Cookies.get('user_password');
}

export const getCardNumber = () => {
    return   Cookies.get('card_number');
}
export const getExpiry = () => {
    return Cookies.get('expiry');
}
export const getPhone = () => {
    return   Cookies.get('phone');
}
export const getZip_Code = () => {
    return Cookies.get('zip_code');
}

export const getStreetNo=()=>{
    Cookies.get('street_no');
}
export const getStreetName=()=>{
    Cookies.get('street_name');
}
export const getCity=()=>{
    Cookies.get('city');
}
export const getState=()=>{
    Cookies.get('state');
}
export const getBirthDate=()=>{
    Cookies.get('birth_date');
}
export const getQuestionId=()=>{
    Cookies.get('question_id');
}
export const getAnswer=()=>{
    Cookies.get('answer');
}

export const setTrackingToken = (value) => {
    Cookies.set('tracking_token', value);
}

export const getTrackingToken = () => {
    return Cookies.get('tracking_token');
}
export const unsetTrackingToken = () => {
    Cookies.remove('tracking_token');
}


export const setCustomerToken = (value) => {
    Cookies.set('customer_token', value);
}
export const getCustomerToken = () => {
    return Cookies.get('customer_token');
}
export const unsetCustomerToken = () => {
    Cookies.remove('customer_token');
}

export const setReferenceNumber = (value) => {
    Cookies.set('reference_number', value);
}
export const getReferenceNumber = () => {
    return Cookies.get('reference_number');
}
export const unsetReferenceNumber = () => {
    Cookies.remove('reference_number');
}


export const unsetUserFirstName = () => {
    Cookies.remove('user_first_name');
}
export const unsetUserLastName = () => {
    Cookies.remove('user_last_name');
}
export const unsetUserEmail = () => {
    Cookies.remove('user_email');
}
export const unsetUserPassword = () => {
    Cookies.remove('user_password');
}

export const unsetExpiry = () => {
    Cookies.remove('expiry');
}
export const unsetCardNumber = () => {
    Cookies.remove('card_number');
}
export const unsetFullSsn = () => {
    Cookies.remove('full_ssn');
}

export const unsetStreetNo=()=>{
    Cookies.remove('street_no');
}
export const unsetStreetName=()=>{
    Cookies.remove('street_name');
}
export const unsetCity=()=>{
    Cookies.remove('city');
}
export const unsetState=()=>{
    Cookies.remove('state');
}
export const unsetBirthDate=()=>{
    Cookies.remove('birth_date');
}
export const unsetQuestionId=()=>{
    Cookies.remove('question_id');
}
export const unsetAnswer=()=>{
    Cookies.remove('answer');
}

export const generateSidebarMenuItems = () => {
    return [
        {
            title: "Dashboard",
            route: "dashboard",
            icon_classes: "sidebar-item-icon ti-home",
            permit: true,
            is_active: isSameRoute('dashboard')
        },
        {
            title: "Merchants",
            route: "merchants",
            icon_classes: "sidebar-item-icon fa fa-users",
            permit: true,
            is_active: isSameRoute('merchants')
        },
        {
            title: "Transactions",
            aria_expands: ["all-transactions", "refunds", "chargeback"].includes(router.currentRoute.value.name),
            sub_routes: ["all-transactions", "refunds", "chargeback"],
            submenu: [
                {
                    title: "All Transactions",
                    route: "all-transactions",
                    permit: hasPermission(constants.permissions.show_all_transaction_of_merchant),
                    is_active: isSameRoute('all-transactions')
                },
                {
                    title: "Refunds",
                    route: "refunds",
                    permit: hasPermission(constants.permissions.show_merchant_refunds),
                    is_active: isSameRoute('refunds')
                },
                {
                    title: "Chargeback",
                    route: "chargeback",
                    permit: hasPermission(constants.permissions.show_merchant_chargebacks),
                    is_active: isSameRoute('chargeback')
                },
            ],
            permit: true,
        },
        {
            title: "Information",
            route: "information",
            icon_classes: "sidebar-item-icon ti-info",
            permit: true,
            is_active: isSameRoute('information')
        },
    ]
}

export const hasPermission = (permission) => {
    return store.getters['auth/getPermissions'][permission?.code]?.permit
}

export const getCurrentRouteQueries = (queriesProxy) => {
    return Object.assign({}, queriesProxy)
}

export const isSameRoute = (route_name) => {
    return router.currentRoute.value.name === route_name
}

export const getFormattedDaterangeFromDates = (start_date = new Date(new Date().setDate(new Date().getDate() - 30)), end_date = new Date()) => {
    return `${start_date.getFullYear()}/${start_date.getMonth() + 1}/${start_date.getDate()} - ${end_date.getFullYear()}/${end_date.getMonth() + 1}/${end_date.getDate()}`
}

export const showNotification = (action, message, type = "default") => {
    notify({
        title: action,
        text: message,
        type: type
    });
}
