import React from "react";
import { OQAD_TimeConst } from "../constants/constants";

const initialState = {
    projectID: '',
    projectName: "",
    projectCode: "",
    projectData:{},
    baseurl:'',   
    companylogo:'',
    splashlogo:'',
    drawerlogo:'',
    imageUploadUrl:'',
    GeoFenceEnable:false,
    GeoFenceRadius:0,
    GFEnable_checkout:false,
    GFRadius_checkout:0,
    CheckOut_PhotoReq:false,
    OQAD_TimeOut:OQAD_TimeConst,
    Clear_storage:false,
    SUP_StorewisePJP:false,
    ManagerAppConfig:"",
    SUP_ManagerDesigList:"",
    DownloadKey:'',
    ShowDBPOSM:false,
    ShowNPND:false,
    ShowNPNDLabel:false,
    ShowImageAudit:false,
    AppDashboardReports:{}, // new
    Show_OldMTDReports:true,
    ShowDashboard:true,

    ShowStoreSearch:false,
    ShowStoreSearchLabel:false,

};

const projectReducer = (state = initialState, action) => {
    switch(action.type) {
        case 'GETPROJECT':
            return {...state};
        case 'SETPROJECT': 
            const pdata=action.data || {}; 
            let newstate={projectID:pdata.pid,projectName:pdata.pname,projectCode:pdata.pcode,projectData:pdata.alldata,baseurl:pdata.baseurl,companylogo:(pdata.companylogo || ''), splashlogo:(pdata.splashlogo || ''),drawerlogo:(pdata.drawerlogo || ''), imageUploadUrl:(pdata.imageUploadUrl || ''),imageUploadUrl:(pdata.imageUploadUrl || ''),
            GeoFenceEnable:(pdata.GeoFenceEnable || false),GeoFenceRadius:(pdata.GeoFenceRadius || 0),GFEnable_checkout:(pdata.GFEnable_checkout || false),SUP_StorewisePJP:(pdata.SUP_StorewisePJP || false),ManagerAppConfig:(pdata.ManagerAppConfig || ""),GFRadius_checkout:(pdata.GFRadius_checkout || 0),CheckOut_PhotoReq:(pdata.CheckOut_PhotoReq!=null?pdata.CheckOut_PhotoReq:false),OQAD_TimeOut:(pdata.OQAD_TimeOut!=null?pdata.OQAD_TimeOut:OQAD_TimeConst),Clear_storage:(pdata.Clear_storage || false), 
            SUP_ManagerDesigList:(pdata.SUP_ManagerDesigList || ""),DownloadKey:(pdata.DownloadKey!=null?pdata.DownloadKey:'') ,ShowDBPOSM:(pdata.ShowDBPOSM!=null?pdata.ShowDBPOSM:false),ShowNPND:(pdata.ShowNPND!=null?pdata.ShowNPND:false),
            Show_OldMTDReports:(pdata.Show_OldMTDReports==1 || pdata.Show_OldMTDReports=="true"?true:false),
            ShowDashboard:(pdata.ShowDashboard==1 || pdata.ShowDashboard=="true"?true:false),
            ShowImageAudit:(pdata.ShowImageAudit!=null?pdata.ShowImageAudit:false) ,ShowStoreSearch:(pdata.ShowStoreSearch!=null?pdata.ShowStoreSearch:false),ShowStoreSearchLabel:(pdata.ShowStoreSearchLabel!=null?pdata.ShowStoreSearchLabel:'') ,ShowNPNDLabel:(pdata.ShowNPNDLabel!=null?pdata.ShowNPNDLabel:false)};   
            
            return Object.assign({},state,newstate);
        case 'SETPROJECTCONFIG': 
                const pdata2=action.data || {}; 
                return {...state,SUP_StorewisePJP:(pdata2.SUP_StorewisePJP || false),};
        case 'SET_DASHBOARD_REPORTS':
            return {...state,AppDashboardReports:action.data};
               
        default:
            return state;
    }
}
export default projectReducer;