import { useCallback, useEffect, useState } from 'react';
import { Navigate } from 'react-router-dom';
import { useGQLClient } from '../context/GQLClientContext';
import { Organization } from 'gql-client';

const owner = {
  id: 'user',
  name: 'Cody',
  email: 'cody@cfb.dev',
  isVerified: true,
  createdAt: '2024-10-22-12:00:00Z',
  updatedAt: '2024-10-22-12:00:00Z',
  gitHubToken: 'token',
};

const domain = {
  id: 'domain',
  branch: 'idk',
  name: 'Domain',
  status: 'Live',
  redirectTo: null,
  createdAt: '2024-10-22-12:00:00Z',
  updatedAt: '2024-10-22-12:00:00Z',
};
const deployment = {
  id: 'deployment',
  domain,
  branch: 'branch',
  commitHash: 'beefb0d',
  commitMessage: 'beef',
  deployerLrn: 'deployer',
  environment: 'Development',
  isCurrent: true,
  status: 'Ready',
  createdBy: owner,
  createdAt: '2024-10-22-12:00:00Z',
  updatedAt: '2024-10-22-12:00:00Z',
};
const member = {
  id: 'member_id',
  member: owner,
  permissions: ['Edit'],
  isPending: false,
  createdAt: '2024-10-22-12:00:00Z',
  updatedAt: '2024-10-22-12:00:00Z',
};

const environmentVariable = {
  id: 'env_var_id',
  environment: 'Development',
  key: 'key',
  value: 'value',
  createdAt: '2024-10-22-12:00:00Z',
  updatedAt: '2024-10-22-12:00:00Z',
};
const project = {
  id: 'project',
  owner,
  deployments: [deployment],
  name: 'Project',
  repository: 'snowball',
  prodBranch: 'main',
  description: 'description',
  template: 'template',
  framework: 'framework',
  webhooks: ['webhook'],
  members: [member],
  environmentVariables: [environmentVariable],
  createdAt: '2024-10-22-12:00:00Z',
  updatedAt: '2024-10-22-12:00:00Z',
};

const organizationMember = {
  id: 'member_id',
  member: owner,
  role: 'Owner',
  createdAt: '2024-10-22-12:00:00Z',
  updatedAt: '2024-10-22-12:00:00Z',
};
const testOrg = {
  id: 'org_id',
  name: 'Test Org',
  slug: 'test',
  projects: [project],
  createdAt: '2024-10-22-12:00:00Z',
  updatedAt: '2024-10-22-12:00:00Z',
  members: [organizationMember],
};
const Index = () => {
  const client = useGQLClient();
  // const [organization, setOrganization] = useState<Organization>(testOrg);

  // const fetchUserOrganizations = useCallback(async () => {
  //   const { organizations } = await client.getOrganizations();
  //   // By default information of first organization displayed
  //   setOrganization(organizations[0]);
  // }, []);
  //
  // useEffect(() => {
  //   fetchUserOrganizations();
  // }, []);

  return (
    <>{Boolean(testOrg) ? <Navigate to={testOrg!.slug} /> : <>Loading</>}</>
  );
};

export default Index;
