import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import Avatar from './avatar';
import DisplayName from './display_name';
import IconButton from './icon_button';
import { defineMessages, injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { me } from '../initial_state';
import RelativeTimestamp from './relative_timestamp';
import Skeleton from 'mastodon/components/skeleton';
import { Link } from 'react-router-dom';
import { counterRenderer } from 'mastodon/components/common_counter';
import ShortNumber from 'mastodon/components/short_number';
import Icon from 'mastodon/components/icon';
import classNames from 'classnames';
const messages = defineMessages({
  follow: { id: 'account.follow', defaultMessage: 'Follow' },
  unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
  unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
  mute_notifications: { id: 'account.mute_notifications', defaultMessage: 'Mute notifications from @{name}' },
  unmute_notifications: { id: 'account.unmute_notifications', defaultMessage: 'Unmute notifications from @{name}' },
  mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  block: { id: 'account.block', defaultMessage: 'Block @{name}' },
});
class VerifiedBadge extends React.PureComponent {
  static propTypes = {
    link: PropTypes.string.isRequired,
    verifiedAt: PropTypes.string.isRequired,
  };
  render () {
    const { link } = this.props;
    return (
      
        
        
      
    );
  }
}
class Account extends ImmutablePureComponent {
  static propTypes = {
    size: PropTypes.number,
    account: ImmutablePropTypes.map,
    onFollow: PropTypes.func.isRequired,
    onBlock: PropTypes.func.isRequired,
    onMute: PropTypes.func.isRequired,
    onMuteNotifications: PropTypes.func.isRequired,
    intl: PropTypes.object.isRequired,
    hidden: PropTypes.bool,
    minimal: PropTypes.bool,
    actionIcon: PropTypes.string,
    actionTitle: PropTypes.string,
    defaultAction: PropTypes.string,
    onActionClick: PropTypes.func,
  };
  static defaultProps = {
    size: 46,
  };
  handleFollow = () => {
    this.props.onFollow(this.props.account);
  };
  handleBlock = () => {
    this.props.onBlock(this.props.account);
  };
  handleMute = () => {
    this.props.onMute(this.props.account);
  };
  handleMuteNotifications = () => {
    this.props.onMuteNotifications(this.props.account, true);
  };
  handleUnmuteNotifications = () => {
    this.props.onMuteNotifications(this.props.account, false);
  };
  handleAction = () => {
    this.props.onActionClick(this.props.account);
  };
  render () {
    const { account, intl, hidden, onActionClick, actionIcon, actionTitle, defaultAction, size, minimal } = this.props;
    if (!account) {
      return (
        
      );
    }
    if (hidden) {
      return (
        <>
          {account.get('display_name')}
          {account.get('username')}
        >
      );
    }
    let buttons;
    if (actionIcon) {
      if (onActionClick) {
        buttons = ;
      }
    } else if (account.get('id') !== me && account.get('relationship', null) !== null) {
      const following = account.getIn(['relationship', 'following']);
      const requested = account.getIn(['relationship', 'requested']);
      const blocking  = account.getIn(['relationship', 'blocking']);
      const muting  = account.getIn(['relationship', 'muting']);
      if (requested) {
        buttons = ;
      } else if (blocking) {
        buttons = ;
      } else if (muting) {
        let hidingNotificationsButton;
        if (account.getIn(['relationship', 'muting_notifications'])) {
          hidingNotificationsButton = ;
        } else {
          hidingNotificationsButton = ;
        }
        buttons = (
          <>
            
            {hidingNotificationsButton}
          >
        );
      } else if (defaultAction === 'mute') {
        buttons = ;
      } else if (defaultAction === 'block') {
        buttons = ;
      } else if (!account.get('moved') || following) {
        buttons = ;
      }
    }
    let muteTimeRemaining;
    if (account.get('mute_expires_at')) {
      muteTimeRemaining = <>· >;
    }
    let verification;
    const firstVerifiedField = account.get('fields').find(item => !!item.get('verified_at'));
    if (firstVerifiedField) {
      verification = <>· >;
    }
    return (
      
        
          
            
            
              
              {!minimal && <> {verification} {muteTimeRemaining}>}
            
          
          {!minimal && (
            
              {buttons}
            
          )}
        
 
       
    );
  }
}
export default injectIntl(Account);