import * as React from 'react';
import gql from 'graphql-tag';
import { inject } from 'mobx-react';

import { IMeQueryProps, MeQuery } from './types';

export const OPPORTUNITIES = gql`
  query opportunities($accountInput: AccountInput){
    me(input: $accountInput) {
      ssn
      opportunities {
        id
        label
        subject
        importance
        expectedOutcome
        status
        category
        description
        ticketId
        script
        callToAction
      }
    }
  }
`;

@inject('authentication')
export default class Query extends React.Component<IMeQueryProps> {
  render() {
    const { authentication: { accountInput }, variables, children, ...rest } = this.props;

    return (
      <MeQuery query={OPPORTUNITIES} variables={{ accountInput, ...variables }} {...rest}>
        {result => children(result)}
      </MeQuery>
    );
  }
}
