import React from "react";
import { useAuth } from "../../hooks";
import { useEffect } from "react";
import { getState } from "../../api";
import { useState } from "react";
import Chart from "react-apexcharts";
import "./home.scss";
import { Link } from "react-router-dom";
import { MagnifyingGlass } from "react-loader-spinner";
export const Home = () => {
const { user } = useAuth();
const [dataset, setDataset] = useState(null);
const [generalStat, setGeneralStat] = useState(null);
const [roomsStats, setRoomsState] = useState(null);
const [isLoad, setIsLoad] = useState(true);
useEffect(() => {
getState().then((res) => {
try {
setIsLoad(false);
console.log(res);
setDataset(res);
setupRoomsStats(res.rooms);
setupGlobalStat({ years: res.years, global: res.global });
} catch (err) {
console.error(err);
}
});
}, []);
const setupRoomsStats = (rooms) => {
setRoomsState(
Object.values(rooms).sort((a, b) => b.room_price - a.room_price),
);
};
const setupGlobalStat = (data) => {
const stats = {
options: {
chart: {
id: "",
},
xaxis: {
categories: [],
},
stroke: {
curve: "smooth",
},
},
series: [
{
name: "",
type: "line",
data: [],
color: "#7b6a9c",
},
],
};
for (let i in data.years) {
if (data.years[i] === 0) {
continue;
}
stats.options.xaxis.categories.push(i);
stats.series[0].data.push(data.years[i]);
}
const component = (