// GlobalStateContext.js
import React, { useState } from "react";
import GlobalStateContext from "./GlobalStateContext";
import { effect, useColorMode } from "@chakra-ui/react";
import { v4 as uuidv4 } from "uuid";

const getRandomDate = (start, end) => {
  const date = new Date(
    start.getTime() + Math.random() * (end.getTime() - start.getTime())
  );
  return date.toISOString();
};

const startDate = new Date(2020, 0, 1); // January 1, 2020
const endDate = new Date(); // Current date

const GlobalStateProvider = ({ children }) => {
  const [isAuthenticate, setIsAuthenticate] = useState(false);
  const [memberIfo, setMemberInfo] = useState();
  const [communityMembers, setCommityMembers] = useState();
  const [slideFromRight, setSlideFormRight] = useState(false);

  const { colorMode, toggleColorMode } = useColorMode();
  const [sponser, setSponser] = useState([
    {
      id: 1,
      sponserName: "John Doe",
      mobileNo: "1234567890",
      sponserAddress: "123 Main St, Springfield, USA",
      accountHolderName: "John Doe",
      bankName: "Example Bank",
      accountNumber: "1234567890",
      bankBranch: "Main Branch",
      branchAddress: "456 Elm St, Springfield, USA",
      ifscCode: "IFSC12345",
      swiftCode: "SWIFT56789",
      routingNumber: "987654321",
      iban: "IBAN987654321",
      accountType: "savings",
      bankPhoneNumber: "9876543210",
      bankEmail: "john.doe@example.com",
      status: true,
      createdAt: "45",
    },
    {
      id: 2,
      sponserName: "Jane Smith",
      mobileNo: "9876543210",
      sponserAddress: "456 Oak St, Metropolis, USA",
      accountHolderName: "Jane Smith",
      bankName: "Another Bank",
      accountNumber: "0987654321",
      bankBranch: "Downtown Branch",
      branchAddress: "789 Pine St, Metropolis, USA",
      ifscCode: "IFSC54321",
      swiftCode: "SWIFT98765",
      routingNumber: "123456789",
      iban: "IBAN123456789",
      accountType: "checking",
      bankPhoneNumber: "1234567890",
      bankEmail: "jane.smith@example.com",
      status: false,
      createdAt: "45",
    },
    {
      id: 3,
      sponserName: "Alice Johnson",
      mobileNo: "1231231234",
      sponserAddress: "789 Pine St, Gotham, USA",
      accountHolderName: "Alice Johnson",
      bankName: "Gotham Bank",
      accountNumber: "5678901234",
      bankBranch: "Uptown Branch",
      branchAddress: "101 Oak St, Gotham, USA",
      ifscCode: "IFSC67890",
      swiftCode: "SWIFT34567",
      routingNumber: "987654321",
      iban: "IBAN345678901",
      accountType: "business",
      bankPhoneNumber: "5556667777",
      bankEmail: "alice.johnson@example.com",
      status: true,
      createdAt: "12",
    },
    {
      id: 4,
      sponserName: "Bob Brown",
      mobileNo: "3213214321",
      sponserAddress: "101 Maple St, Smallville, USA",
      accountHolderName: "Bob Brown",
      bankName: "Smallville Credit Union",
      accountNumber: "5432109876",
      bankBranch: "Main Street Branch",
      branchAddress: "202 Pine St, Smallville, USA",
      ifscCode: "IFSC43210",
      swiftCode: "SWIFT87654",
      routingNumber: "123456789",
      iban: "IBAN567890123",
      accountType: "savings",
      bankPhoneNumber: "8889990000",
      bankEmail: "bob.brown@example.com",
      status: true,
      createdAt: "7",
    },
    {
      id: 5,
      sponserName: "Charlie Davis",
      mobileNo: "5555555555",
      sponserAddress: "202 Birch St, Star City, USA",
      accountHolderName: "Charlie Davis",
      bankName: "Star City Bank",
      accountNumber: "9876543210",
      bankBranch: "Downtown Branch",
      branchAddress: "303 Oak St, Star City, USA",
      ifscCode: "IFSC55555",
      swiftCode: "SWIFT00000",
      routingNumber: "111223344",
      iban: "IBAN999988887",
      accountType: "checking",
      bankPhoneNumber: "1112223333",
      bankEmail: "charlie.davis@example.com",
      status: false,
      createdAt: "4",
    },
    {
      id: 6,
      sponserName: "Daniel Evans",
      mobileNo: "4444444444",
      sponserAddress: "303 Cedar St, Central City, USA",
      accountHolderName: "Daniel Evans",
      bankName: "Central City Bank",
      accountNumber: "4444555566",
      bankBranch: "Uptown Branch",
      branchAddress: "404 Elm St, Central City, USA",
      ifscCode: "IFSC44444",
      swiftCode: "SWIFT11111",
      routingNumber: "555666777",
      iban: "IBAN4444555566",
      accountType: "business",
      bankPhoneNumber: "4445556666",
      bankEmail: "daniel.evans@example.com",
      status: true,
      createdAt: "2",
    },
    {
      id: 7,
      sponserName: "Ella Fitzgerald",
      mobileNo: "3333333333",
      sponserAddress: "404 Elm St, Coast City, USA",
      accountHolderName: "Ella Fitzgerald",
      bankName: "Coast City Bank",
      accountNumber: "3333444455",
      bankBranch: "Downtown Branch",
      branchAddress: "505 Cedar St, Coast City, USA",
      ifscCode: "IFSC77777",
      swiftCode: "SWIFT22222",
      routingNumber: "888999000",
      iban: "IBAN888999000",
      accountType: "savings",
      bankPhoneNumber: "7778889999",
      bankEmail: "ella.fitzgerald@example.com",
      status: false,
      createdAt: "9",
    },
    {
      id: 8,
      sponserName: "Frank Green",
      mobileNo: "2222222222",
      sponserAddress: "505 Ash St, Keystone City, USA",
      accountHolderName: "Frank Green",
      bankName: "Keystone City Bank",
      accountNumber: "2222333344",
      bankBranch: "Main Branch",
      branchAddress: "606 Birch St, Keystone City, USA",
      ifscCode: "IFSC88888",
      swiftCode: "SWIFT33333",
      routingNumber: "444555666",
      iban: "IBAN444555666",
      accountType: "checking",
      bankPhoneNumber: "2222333444",
      bankEmail: "frank.green@example.com",
      status: true,
      createdAt: "8",
    },
    {
      id: 9,
      sponserName: "Grace Hall",
      mobileNo: "1111111111",
      sponserAddress: "606 Willow St, Hub City, USA",
      accountHolderName: "Grace Hall",
      bankName: "Hub City Bank",
      accountNumber: "1111222233",
      bankBranch: "Downtown Branch",
      branchAddress: "707 Cedar St, Hub City, USA",
      ifscCode: "IFSC99999",
      swiftCode: "SWIFT44444",
      routingNumber: "555566677",
      iban: "IBAN555566677",
      accountType: "business",
      bankPhoneNumber: "1111222333",
      bankEmail: "grace.hall@example.com",
      status: true,
      createdAt: "1",
    },
    {
      id: 10,
      sponserName: "Henry Ingram",
      mobileNo: "6666666666",
      sponserAddress: "707 Spruce St, Fawcett City, USA",
      accountHolderName: "Henry Ingram",
      bankName: "Fawcett City Bank",
      accountNumber: "6666777788",
      bankBranch: "Main Street Branch",
      branchAddress: "808 Oak St, Fawcett City, USA",
      ifscCode: "IFSC66666",
      swiftCode: "SWIFT55555",
      routingNumber: "999000111",
      iban: "IBAN999000111",
      accountType: "savings",
      bankPhoneNumber: "6666777888",
      bankEmail: "henry.ingram@example.com",
      status: false,
      createdAt: "6",
    },
    {
      id: 11,
      sponserName: "Grace Hall",
      mobileNo: "1111111111",
      sponserAddress: "606 Willow St, Hub City, USA",
      accountHolderName: "Grace Hall",
      bankName: "Hub City Bank",
      accountNumber: "1111222233",
      bankBranch: "Downtown Branch",
      branchAddress: "707 Cedar St, Hub City, USA",
      ifscCode: "IFSC99999",
      swiftCode: "SWIFT44444",
      routingNumber: "555566677",
      iban: "IBAN555566677",
      accountType: "business",
      bankPhoneNumber: "1111222333",
      bankEmail: "grace.hall@example.com",
      status: true,
      createdAt: "1",
    },
    {
      id: 12,
      sponserName: "Henry Ingram",
      mobileNo: "6666666666",
      sponserAddress: "707 Spruce St, Fawcett City, USA",
      accountHolderName: "Henry Ingram",
      bankName: "Fawcett City Bank",
      accountNumber: "6666777788",
      bankBranch: "Main Street Branch",
      branchAddress: "808 Oak St, Fawcett City, USA",
      ifscCode: "IFSC66666",
      swiftCode: "SWIFT55555",
      routingNumber: "999000111",
      iban: "IBAN999000111",
      accountType: "savings",
      bankPhoneNumber: "6666777888",
      bankEmail: "henry.ingram@example.com",
      status: false,
      createdAt: "6",
    },
  ]);

  const [investment, setInvestment] = useState([
    {
      imgSrc:
        "https://images.unsplash.com/photo-1667489022797-ab608913feeb?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw5fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=800&q=60",
      title: "Multi Family Residence Portfolio",
      sponsor: "KKR",
      annReturn: "12.5%",
      annYield: "12.5%",
      minInvests: ",00 $0",
      targClose: "24 December",
      holdingPer: "5-7 years",
      progressValue: 80,
      status: "Available"
    },
    {
      imgSrc:
        "https://images.unsplash.com/photo-1667489022797-ab608913feeb?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw5fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=800&q=60",
      title: "Multi Family Residence Portfolio",
      sponsor: "KKR",
      annReturn: "12.5%",
      annYield: "12.5%",
      minInvests: ",00 $0",
      targClose: "24 December",
      holdingPer: "5-7 years",
      progressValue: 80,
      status: "Upcomming"
    },
    {
      imgSrc:
        "https://images.unsplash.com/photo-1667489022797-ab608913feeb?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw5fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=800&q=60",
      title: "Multi Family Residence Portfolio",
      sponsor: "KKR",
      annReturn: "12.5%",
      annYield: "12.5%",
      minInvests: ",00 $0",
      targClose: "24 December",
      holdingPer: "5-7 years",
      progressValue: 80,
      status: "Closed"
    },
  ]);

  const [rateExchange, setRateExchange] = useState([
    {
      id: uuidv4(),
      fromCurr: "USD $",
      toCurr: "BHD .د.ب;",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "USD $",
      toCurr: "KWD ·د.ك",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "USD $",
      toCurr: "OMR ﷼.",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "USD $",
      toCurr: "QAR ﷼.",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "USD $",
      toCurr: "SAR ﷼.",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "USD $",
      toCurr: "AED د.إ. ",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },

    {
      id: uuidv4(),
      fromCurr: "AED د.إ. ",
      toCurr: "USD $",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "SAR ﷼.",
      toCurr: "USD $",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "QAR ﷼.",
      toCurr: "USD $",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },

    {
      id: uuidv4(),
      fromCurr: "BHD .د.ب;",
      toCurr: "USD $",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "KWD ·د.ك",
      toCurr: "USD $",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
    {
      id: uuidv4(),
      fromCurr: "OMR ﷼.",
      toCurr: "USD $",
      effectFrom: getRandomDate(startDate, endDate),
      effectTill: getRandomDate(startDate, endDate),
      rate: 2.66,
    },
  ]);

  const [InvestorDetails, setInvestorDetails] = useState([
    {
      id: 1,
      InvestorName: "ICC",
      Sponsor: "Adani",
      InvestmentAmount: "1000000",
      Action: "Distribute",
    },
    {
      id: 2,
      InvestorName: "ECHO Investment",
      Sponsor: "Tata",
      InvestmentAmount: "2500000",
      Action: "Distribute",
    },
  ]);

  const [pendingRequest, setPendingRequest] = useState([
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: getRandomDate(startDate, endDate),
      Distribution: "lorem ipsum dummy text",
      charge: "500",
      year: "2024",
      quater: "Q 1",
      amount: 1000,
    },
  ]);

  const [viewHistory, setViewHistory] = useState([
    {
      id: uuidv4(),
      date: "2024-01-15",
      Distribution: "Office supplies",
      charge: "200.50",
      year: "2024",
      quarter: "Q1",
      amount: 1500,
    },
    {
      id: uuidv4(),
      date: "2024-02-10",
      Distribution: "Marketing expenses",
      charge: "450.00",
      year: "2024",
      quarter: "Q1",
      amount: 2000,
    },
    {
      id: uuidv4(),
      date: "2024-03-05",
      Distribution: "Software subscription",
      charge: "300.75",
      year: "2024",
      quarter: "Q1",
      amount: 1200,
    },
    {
      id: uuidv4(),
      date: "2024-04-18",
      Distribution: "Travel expenses",
      charge: "600.30",
      year: "2024",
      quarter: "Q2",
      amount: 2500,
    },
    {
      id: uuidv4(),
      date: "2024-05-22",
      Distribution: "Consulting fees",
      charge: "800.00",
      year: "2024",
      quarter: "Q2",
      amount: 3000,
    },
    {
      id: uuidv4(),
      date: "2024-06-14",
      Distribution: "Office rent",
      charge: "1200.25",
      year: "2024",
      quarter: "Q2",
      amount: 3500,
    },
    {
      id: uuidv4(),
      date: "2024-07-09",
      Distribution: "Utilities",
      charge: "150.40",
      year: "2024",
      quarter: "Q3",
      amount: 1000,
    },
    {
      id: uuidv4(),
      date: "2024-08-29",
      Distribution: "Employee training",
      charge: "500.00",
      year: "2024",
      quarter: "Q3",
      amount: 1800,
    },
    {
      id: uuidv4(),
      date: "2024-09-13",
      Distribution: "Website maintenance",
      charge: "350.65",
      year: "2024",
      quarter: "Q3",
      amount: 1400,
    },
    {
      id: uuidv4(),
      date: "2024-10-23",
      Distribution: "Advertising",
      charge: "900.50",
      year: "2024",
      quarter: "Q4",
      amount: 2200,
    },
    {
      id: uuidv4(),
      date: "2024-10-23",
      Distribution: "Advertising",
      charge: "900.50",
      year: "2024",
      quarter: "Q4",
      amount: 2200,
    },
    {
      id: uuidv4(),
      date: "2024-10-23",
      Distribution: "Advertising",
      charge: "900.50",
      year: "2024",
      quarter: "Q4",
      amount: 2200,
    },
  ]);

  return (
    <GlobalStateContext.Provider
      value={{
        isAuthenticate,
        setIsAuthenticate,
        memberIfo,
        setMemberInfo,
        communityMembers,
        setCommityMembers,
        sponser,
        setSponser,
        colorMode,
        toggleColorMode,
        slideFromRight,
        setSlideFormRight,

        InvestorDetails,
        setInvestorDetails,
        investment,
        setInvestment,
        rateExchange,
        setRateExchange,
        pendingRequest,
        setPendingRequest,
        viewHistory,
        setViewHistory,
      }}
    >
      {children}
    </GlobalStateContext.Provider>
  );
};
export default GlobalStateProvider;
