import React, { Component } from "react";
import FlatButton from "material-ui/FlatButton";
import Dialog from "material-ui/Dialog";
import { slideInRight } from "react-animations";
import Radium, { StyleRoot } from "radium";
var urlExists = require("url-exists");
var path = require("path");
class ErrorPage extends Component {
  constructor(props) {
    super(props);

    this.state = {
      open: false,
      alertmsg: "This page does not exist"
    };
  }

  componentDidMount = () => {
    console.log("error_page", window.location);
    let self = this;
    // this.props.history.push("/");
    let paths = window.location.href;
    console.log("error_page", paths);
    urlExists(path, function(err, exists) {
      if (exists) {
        console.log(exists); // true
      } else {
        console.log("err", err);
        let path_name = window.location.pathname;
        if (
          path_name !== "/signup_step-1" ||
          path_name !== "/signup_step-2" ||
          path_name !== "/share" ||
          path_name !== "/set_relation" ||
          path_name !== "/parent" ||
          path_name !== "/Connect/:user_id/:relative_user_id" ||
          path_name !== "/Contest/:contest_id/:user_id" ||
          path_name !== "/SocialShare" ||
          path_name !== "/add_relation" ||
          path_name !== "/family" ||
          path_name !== "/phone_number" ||
          path_name !== "/skill_test_questions" ||
          path_name !== "/family_share" ||
          path_name !== "/view_profile" ||
          path_name !== "/my_connections" ||
          path_name !== "/edit_personal_info" ||
          path_name !== "/edit_address" ||
          path_name !== "/welcome_activation" ||
          path_name !== "/perks" ||
          path_name !== "/freebie3" ||
          path_name !== "/freebie2" ||
          path_name !== "/freebie1" ||
          path_name !== "/FamilyShare1" ||
          path_name !== "/contest3" ||
          path_name !== "/contest2" ||
          path_name !== "/contest1" ||
          path_name !== "/account_activated" ||
          path_name !== "/index" ||
          path_name !== "/drawer" ||
          path_name !== "/report"
        ){
          console.log("err")
            self.props.history.push("/");
        }
      }
    });
    // path.exists(paths, function(exists) {
    //     console.log("exists",exists)
    //     if (exists) {
    //         console.log("exists",exists)
    //     }
    //     else{
    //         console.log("exists",exists)
    //     }
    //   });
  };

  render() {
    return (
      <center>
        <div className="background-images">
          <div className="background_color">
            <div className="container-fluid">
              <div style={styles.root}>
                <Dialog
                  actions={
                    <FlatButton
                      label="Close"
                      onClick={() =>
                        this.state.nocontest
                          ? this.props.history.push("/perks")
                          : this.handleClose()
                      }
                    />
                  }
                  modal={false}
                  open={this.state.open}
                >
                  {this.state.alertmsg}
                </Dialog>
              </div>
            </div>
          </div>
        </div>
      </center>
    );
  }
}

const styles = {
  button: { margin: 12 },
  slideInRight: {
    animation: "x 1s",
    animationName: Radium.keyframes(slideInRight, "slideInRight")
  }
};

export default ErrorPage;
