import React, { useReducer } from "react";
import { ConfigureContext } from './ConfigureContext';
import { anniversaryReducer } from "./configureReducer";



const INITIAL_STATE: VixonicData = {
    downloadsPath: '',
    parameters: {
        abbreviatedMonths: false,
        animationMode: "",
        animationOrder: false,
        animationSpeed: 1.5,
        animationTime: "",
        backgroundImage: { id: "", filename: "", _isAsset: true },
        apiDomain: "",
        containerColumns: "",
        containerRows: "",
        containerRowsGap: "",
        containerColumnsGap:"",
        dataMode: "",
        dateAlignment: "center",
        dateDayFormat: { font: { filename: '', id: '' ,_isAsset: true }, fontSize: 55, alignment: { horizontal: "center" }, fontColor: "" ,  },
        dateEnabled: true,
        dateMonthFormat: { font: { filename: '', id: '',_isAsset: true }, fontSize: 20, alignment: { horizontal: "center" }, fontColor: "" },
        datePosition: 1,
        datePrimaryColor: "",
        dateStyle: "circle",
        descriptionEnabled: true,
        descriptionFormat: { font: { filename: '', id: '',_isAsset: true }, fontSize: 3.8, alignment: { horizontal: "center" }, fontColor: "" },
        optionalEnabled: true,  
        optionalFormat: { font: { filename: '', id: '',_isAsset: true }, fontSize: 3.8, alignment: { horizontal: "center" }, fontColor: "" },
        excludePast: false,
        imageAlignment: "center",
        imageEnabled: true,
        imagePosition: 0,
        imageStyle: "normal",
        imageSize: 50,
        itemMargins: "",
        msj0: "",
        nameFormat: { font: { filename: '', id: '' ,_isAsset: true}, fontSize: 3.8, alignment: { horizontal: "center" }, fontColor: "" },
        orientation: "",
        padding: "",
        photosMode: "",
        photosZip: { id: "0fb559ec-5da3-4b2d-95c4-d9623754c841", filename: "0fb559ec-5da3-4b2d-95c4-d9623754c841.zip", extension: "zip",_isAsset: true },
        template: "",
        textAlignment: "center",
        textPosition: 0,
        updateTime: 600000,
        urlBaseApi: "",
        imageMargin: "",
        textMargin: "",
        dateMargin: "",
        separator: false
    }
}

interface props {
    children: JSX.Element | JSX.Element[]
}

export const AnniversaryProvider = ({ children }: props) => {

    const [configureState, dispatch] = useReducer(anniversaryReducer, INITIAL_STATE)


    const addConfiguration = (configure: VixonicData) => {
        dispatch({ type: "addConfigure", payload: configure })
    }

    return (
        <ConfigureContext.Provider value={{ configureState, addConfiguration }}>
            {children}
        </ConfigureContext.Provider>
    )
}

