import React, { FC, useState, useEffect } from "react";
import { useParams } from "react-router-dom";
import { ProjectPage } from "../pages/ProjectPage";
import ProjectVM from "../viewModels/ProjectVM";
import { Constants } from "../utils/Constants";
import { Project } from "../types/Project";
import { Ticket } from "../types/Ticket";
import { User } from "../types/User";

export const ProjectController: FC = () => {
  // const [project, setProject] = useState({} as Project);
  const [isLoading, setIsLoading] = useState(false);

  // const { id } = useParams();

  // const getProject: Function = (id: number) => {
  //   fetch(`${Constants.getProjectURI}/${id}`)
  //     .then(res => res.json())
  //     .catch(err => console.log(err))
  //     .then(data => setProject(data))
  //     .finally(() => setIsLoading(false));
  // };

  // useEffect(() => {
  //   getProject(id);
  // }, []);

  // const viewModel = new ProjectVM(project);
  // console.log(viewModel.getMembers());

  const tickets: Ticket[] = [
    {
      id: 1,
      title: "Ticket #1",
      status: "Done"
    },
    {
      id: 2,
      title: "Ticket #2",
      status: "To Do"
    }
  ];

  const users: User[] = [
    {
      id: "1",
      picture:
        "data:image/jpeg;base64,[encoded data, 8156 characters]"
    },
    {
      id: "2",
      picture:
        "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAM1BMVEUKME7///+El6bw8vQZPVlHZHpmfpHCy9Ojsbzg5ekpSmTR2N44V29XcYayvsd2i5yTpLFbvRYnAAAJcklEQVR4nO2d17arOgxFs+kkofz/154Qmg0uKsuQccddT/vhnOCJLclFMo+//4gedzcApf9B4srrusk+GsqPpj+ypq7zVE9LAdLWWVU+Hx69y2FMwAMGyfusLHwIpooyw9IAQfK+8naDp3OGHvZ0FMhrfPMgVnVjC2kABOQ1MLvi0DEIFj1ILu0LU2WjNRgtSF3pKb4qqtd9IHmjGlJHlc09IHlGcrQcPeUjTAySAGNSkQlRhCCJMGaUC0HSYUx6SmxFAtJDTdylsr4ApC1TY0yquKbCBkk7qnYVzPHFBHkBojhVJWviwgPJrsP4qBgTgbQXdsesjm4pDJDmIuswVZDdFx0ENTtkihoeqSDXD6tVxOFFBHnd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K/AZ8vGr3caTliuzeFNeCJTgafpKlhHd2WP1sy1LqDF798gjKJPLqDr9keoTd43+NyNzC1CI8Xy2lcPtOaVBI5IiAWyQ3e125AcKoXs2Djhy5eVc3KiBxREIPkhjBiLhIjU++4T91IbggjRiCJLSEIwWGddkEaxlVN5KCArPHk8mXVpHk8FHH7JL3n5dPA7C90q7XkeFJucacNmGXeRfswLE71HA79efaGiCN/Ofjmfmtcp8X10tIsqCacV5xfRWjNUiXGYbovWgyFYHcQLak15K9oM5zqmgaeKsHJetbSHfSPzXOiw/rxE9YH4CXaUpsZ0ztemFurP95Jpyvrd29YTpIZr7cEJHqfc7Wl0PFm2+yJR70udaokKFtGPTdm8WdQe24+HmVLlueboWQquBcYYVH2vEzfh8kCks1p90eWsLCyZ8qK7E86Oe+3XYFnBuiWdth20UqZR5SvMoyPg3WNauJipi0LMTQgVq5xUUlZcrPsopPHJ926z8pm7xyFLrH/PxpHSoXKdWgXsLn1scZn1ZDd/2vszN3lt254qkE+qu3yoqLM+ghN3Qz2qcVzUC/ZMFsK/alU6l0OWV/bQz6v6yYbyuN5BaZ4A7Y30vs/PPksS2+qzlvfF7OQmzzcL7W+xa7OIfRuVdtn/tdvdFLnL4OTKcm2W16PmWc4FWWXNSlWM2n3D+uPxuyrcfo74aP+Ac30a82+oLmfAAAAAElFTkSuQmCC"
    },
    {
      id: "3",
      picture:
        "data:image/jpeg;base64,[encoded data, 10436 characters]"
    },
    {
      id: "4",
      picture:
        "data:image/jpeg;base64,[encoded data, 12112 characters]"
    }
  ];

  const project: Project = {
    id: 1,
    title: "Project Title",
    description: "What is it about",
    progression: 25,
    tickets: tickets,
    users: users,
    plannedEnding: "2020-02-17 15:51:02.787373"
  };

  const viewModel = new ProjectVM(project);

  return isLoading ? <p>Loading ...</p> : <ProjectPage viewModel={viewModel} />;
};
