import React, {Component} from "react";
import Index from "./../app";
import {auth, retry} from "podauth/src/auth";


//strings
import {serverConfig} from "../constants/connection";

//actions

//components
import SupportModule from "./SupportModule";

//styling

//statics

//functions


export default class Authenticator extends Component {
  constructor(props) {
    super(props);
    this.state = {
      token: null,
    }
    auth({
      clientId: "88413l69cd4051a039cf115ee4e073",
      scope: "social:write",
      ssoBaseUrl: "https://accounts.pod.ir/oauth2",
      onNewToken: token => this.setState({token})
    });
  }

  render() {
    const {token} = this.state;
    if (!token) {
      return null;
    }
    const props = {
/*      supportMode: {
        threadId: 1435053,
        autoShowing: true,
        hideBadge: false,
        onClose() {
          console.log("Closed")
        },
        onOpen() {
          console.log("Opened")
        },
        onLoading(result) {
          console.log("Loading", result)
        },
        onReady(changeThread) {
          window.changeThread = changeThread;
        }
      },*/
      token,
      onRetryHook(e) {
        return retry();
      },
      ...serverConfig()
    }
    return <SupportModule {...props}>
      <Index {...props}/>
    </SupportModule>
  }

}
