import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import Link from './Link'
import { bindActionCreators } from 'redux'
import Thumbnail from './Thumbnail'
import Icon from './Icon'
import URILink from './URILink'
import SpotifyAuthenticationFrame from '../components/Fields/SpotifyAuthenticationFrame'
import LastfmAuthenticationFrame from '../components/Fields/LastfmAuthenticationFrame'
import GeniusAuthenticationFrame from '../components/Fields/GeniusAuthenticationFrame'
import Snapcast from '../components/Snapcast'
import * as uiActions from '../services/ui/actions'
import * as coreActions from '../services/core/actions'
import * as mopidyActions from '../services/mopidy/actions'
import * as pusherActions from '../services/pusher/actions'
import * as spotifyActions from '../services/spotify/actions'
import * as lastfmActions from '../services/lastfm/actions'
import * as geniusActions from '../services/genius/actions'
class Services extends React.Component{
constructor(props){
super(props);
this.state = {
country: this.props.spotify.country,
locale: this.props.spotify.locale,
input_in_focus: null
}
}
componentDidMount(){
if ((this.props.spotify.enabled || this.props.spotify.authorization) && (!this.props.spotify.me || this.props.core.users[this.props.spotify.me.id] === undefined)){
this.props.spotifyActions.getMe();
}
if (this.props.lastfm.authorization && this.props.core.users["lastfm:user:"+this.props.lastfm.authorization.name] === undefined){
this.props.lastfmActions.getMe();
}
if (this.props.genius.authorization && (!this.props.genius.me || this.props.core.users["genius:user:"+this.props.genius.me.id] === undefined)){
this.props.geniusActions.getMe();
}
}
componentWillReceiveProps(newProps){
var changed = false
var state = this.state
if (newProps.spotify.country != this.state.country && this.state.input_in_focus != 'country'){
state.country = newProps.spotify.country
changed = true
}
if (newProps.spotify.locale != this.state.locale && this.state.input_in_focus != 'locale'){
state.locale = newProps.spotify.locale
changed = true
}
if (changed){
this.setState(state)
}
}
handleBlur(name, value){
this.setState({input_in_focus: null})
var data = {}
data[name] = value
this.props.coreActions.set(data)
}
renderSpotify(){
var user_object = (this.props.spotify.me && this.props.core.users[this.props.spotify.me.uri] ? this.props.core.users[this.props.spotify.me.uri] : null);
if (user_object){
var user = (
Mopidy-Spotify extension is not running - you will not be able to play any Spotify tracks