import {createAppContainer, createSwitchNavigator} from 'react-navigation';
import {createStackNavigator, TransitionPresets} from 'react-navigation-stack';
import {
  fromLeft,
  fromRight,
  fromBottom,
  fromTop,
} from 'react-navigation-transitions';
import TestImage from './pages/news/testingImage';
import SimpleAddApartment from './pages/oneClickRental/simpleAddApartment';
import ProblemCase from './pages/problems/problemCase';
import List from './pages/list/list';
import InfoForGuest from './pages/info/infoForGuest';
import Detail from './pages/detail/detail';
import splash from './pages/splash/splashScreen';
import {TabNav} from './common/tab-nav';
import HelpSelect from './pages/help/helpSelect';
import SelectApartmentByOneClickRental from './pages/oneClickRental/selectApartmentByOneClickRental';
import Tutorial from './pages/tutorial/tutorial';
import SelectChar from './pages/select/selectChar';
import Chat from './pages/chat/chat';
import ImageDetails from './pages/chat/imageDetails';
import Signature from './pages/signature/signature';
import SignatureView from './pages/signature/signatureView';
import ForgotPassword from './pages/signup/forgotPassword';
import ApartmentDetails from './pages/addApartment/apartmentDetails';
import ApartmentNameAddressEdit from './pages/addApartment/apartmentNameAddressEdit';
import GetAparmentRef from './pages/addApartment/getAparmentRef';
import UploadImage from './pages/addApartment/upLoadImage';
import ApartmentImageDetails from './pages/addApartment/apartmentImageDetails';
import CropImage from './pages/addApartment/cropImage';
import AddTenant from './pages/addApartment/addTenant';
import Signin from './pages/signIn/signin';
import Signup from './pages/signup/signup';
import WechatSignup from './pages/signup/wechatSignup';
import BannerDetails from './pages/bannerDetails/bannerDetails';
import signUpVerify from './pages/signup/signUpVerify';
import Payment from './pages/profile/payment';
import Card from './pages/profile/card';
import Receipt from './pages/receipt/receipt';
import HistoryDetails from './pages/history/historyDetails';
import AlipayWebView from './pages/history/AlipayWebView';
import ReceiptDetails from './pages/receipt/receiptDetails';
import RepairDetails from './pages/repair/repairDetails';
import PropertyDetails from './pages/property/propertyDetails';
import Add from './pages/add/add';
import SelectApartment from './pages/contract/selectApartment';
import SelectContract from './pages/contract/selectContract';
import SelectContracts from './pages/contract/selectContracts';
import ContractData from './pages/contract/contractData';
import NewContractData from './pages//contract/newContractData';
import Lease from './pages/contract/lease';
import NewLease from './pages/contract/newLease';
import ServicePayment from './pages/contract/servicePayment';
import NewsDetails from './pages/news/newsDetails';
import News from './pages/news/news';
import Property from './pages/property/property';
import IndustrialBuilding from './pages/property/industrialBuilding';
import Repair from './pages/repair/repair';
import PushNotificationTest from './common/pushNotificationTest';
import SyncApartment from './pages/syncApartment/syncApartment';
import RepresentativeContractData from './pages/contract/representative/representativeContractData';
import OneClickRental from './pages/oneClickRental/oneClickRental';

function generateRoute(path, screen) {
  return {
    path,
    screen,
  };
}

const guestRouterMap = {
  infoForGuest: generateRoute('./InfoForGuest', InfoForGuest),
  news: generateRoute('/news', News),
  newsDetails: generateRoute('/newsDetails', NewsDetails),
  bannerDetails: generateRoute('/bannerDetails', BannerDetails),
  repair: generateRoute('/repair', Repair),
  repairDetails: generateRoute('/repairDetails', RepairDetails),
  property: generateRoute('/property', Property),
  industrialBuilding: generateRoute('/industrialBuilding', IndustrialBuilding),
  propertyDetails: generateRoute('/propertyDetails', PropertyDetails),
  oneClickRental: generateRoute('/oneClickRental', OneClickRental),
  simpleAddApartment: generateRoute('/simpleAddApartment', SimpleAddApartment),
  apartmentNameAddressEdit: generateRoute(
    '/apartmentNameAddressEdit',
    ApartmentNameAddressEdit,
  ),
  selectApartmentByOneClickRental: generateRoute(
    '/selectApartmentByOneClickRental',
    SelectApartmentByOneClickRental,
  ),
};

const stackRouterMap = {
  list: generateRoute('/list', List),
  detail: generateRoute('/detail', Detail),
  apartmentDetails: generateRoute('/apartmentDetails', ApartmentDetails),
  apartmentImageDetails: generateRoute(
    '/apartmentImageDetails',
    ApartmentImageDetails,
  ),
  problemCase: generateRoute('/problemCase', ProblemCase),
  testImage: generateRoute('/testImage', TestImage),
  news: generateRoute('/news', News),
  repair: generateRoute('/repair', Repair),
  property: generateRoute('/property', Property),
  industrialBuilding: generateRoute('/industrialBuilding', IndustrialBuilding),
  getApartmentRef: generateRoute('/getApartmentRef', GetAparmentRef),
  uploadImage: generateRoute('/uploadImage', UploadImage),
  cropImage: generateRoute('/cropImage', CropImage),
  signature: generateRoute('/signature', Signature),
  signatureView: generateRoute('/signatureView', SignatureView),
  addTenant: generateRoute('/addTenant', AddTenant),
  signin: generateRoute('/signin', Signin),
  signup: generateRoute('/signup', Signup),
  wechatSignup: generateRoute('/wechatSignup', WechatSignup),
  signUpVerify: generateRoute('/signUpVerify', signUpVerify),
  payment: generateRoute('/payment', Payment),
  card: generateRoute('/card', Card),
  helpSelect: generateRoute('/helpSelect', HelpSelect),
  add: generateRoute('/add', Add),
  receipt: generateRoute('/receipt', Receipt),
  receiptDetails: generateRoute('/receiptDetails', ReceiptDetails),
  apartmentNameAddressEdit: generateRoute(
    '/apartmentNameAddressEdit',
    ApartmentNameAddressEdit,
  ),
  selectApartmentByOneClickRental: generateRoute(
    '/selectApartmentByOneClickRental',
    SelectApartmentByOneClickRental,
  ),
  selectApartment: generateRoute('/selectApartment', SelectApartment),
  selectContract: generateRoute('/selectContract', SelectContract),
  selectContracts: generateRoute('/selectContracts', SelectContracts),
  representativeContractData: generateRoute(
    '/representativeContractData',
    RepresentativeContractData,
  ),
  bannerDetails: generateRoute('/bannerDetails', BannerDetails),
  newsDetails: generateRoute('/newsDetails', NewsDetails),
  contractData: generateRoute('/contractData', ContractData),
  newContractData: generateRoute('/newContractData', NewContractData),
  syncApartment: generateRoute('/syncApartment', SyncApartment),
  historyDetails: generateRoute('/historyDetails', HistoryDetails),
  alipayWebView: generateRoute('/alipayWebView', AlipayWebView),
  repairDetails: generateRoute('/repairDetails', RepairDetails),
  propertyDetails: generateRoute('/propertyDetails', PropertyDetails),
  forgotPassword: generateRoute('/forgotPassword', ForgotPassword),
  oneClickRental: generateRoute('/oneClickRental', OneClickRental),
  lease: generateRoute('/lease', Lease),
  newLease: generateRoute('/newLease', NewLease),
  // infoForGuest: generateRoute('/infoForGuest', InfoForGuest),
  servicePayment: generateRoute('/servicePayment', ServicePayment),
  pushNotificationTest: generateRoute(
    '/pushNotificationTest',
    PushNotificationTest,
  ),
  chat: generateRoute('/chat', Chat),
  simpleAddApartment: generateRoute('/simpleAddApartment', SimpleAddApartment),
  imageDetails: generateRoute('/imageDetails', ImageDetails),
  main: TabNav,
  //SelectChar:generateRoute('/SelectChar',SelectChar)
};

const handleCustomTransition = ({scenes}) => {
  const prevScene = scenes[scenes.length - 2];
  const nextScene = scenes[scenes.length - 1];
  console.log(scenes.length);
  // Custom transitions go there
  if (
    prevScene &&
    prevScene.route.routeName === 'main' &&
    nextScene.route.routeName === 'add'
  ) {
    return fromBottom(500);
  } else if (
    prevScene &&
    prevScene.route.routeName === 'add' &&
    nextScene.route.routeName === 'main'
  ) {
    return fromTop(500);
  }
  return fromRight();
};

const stackNavigate = createStackNavigator(stackRouterMap, {
  initialRouteName: 'main',
  headerMode: 'none',
  defaultNavigationOptions: {
    gestureEnabled: false,
    cardOverlayEnabled: false,
    ...TransitionPresets.SlideFromRightIOS,
  },
});

const guestStackNavigate = createStackNavigator(guestRouterMap, {
  initialRouteName: 'infoForGuest',
  headerMode: 'none',
  defaultNavigationOptions: {
    gestureEnabled: false,
    cardOverlayEnabled: false,
    ...TransitionPresets.SlideFromRightIOS,
  },
});

const InitialNavigator = createSwitchNavigator({
  splash: splash,
  Tutorial: Tutorial,
  mainPage: stackNavigate,
  SelectChar: SelectChar,
  guest: guestStackNavigate,
});

const Router = createAppContainer(InitialNavigator);

export default Router;
