<!--
The MIT License (MIT)

Copyright (c) 2022 rick barrette

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->

<!-- somewhere in your document include the Javascript -->
<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>

<!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below -->
<script>
  intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= Setting.host_name %>/qbo/authenticate'});
</script>

<table >
  <tbody>
  
    <tr>
      <th><%=t(:label_client_id)%></th>
      <td>
        <input 
          type="text" 
          style="width:350px" 
          id="settingsOAuthConsumerKey" 
          value="<%= settings['settingsOAuthConsumerKey'] %>" 
          name="settings[settingsOAuthConsumerKey]" >
      </td>
    </tr>

    <tr>
      <th><%=t(:label_client_secret)%></th>
      <td>
        <input 
          type="text" 
          style="width:350px" 
          id="settingsOAuthConsumerSecret"
          value="<%= settings['settingsOAuthConsumerSecret'] %>"
          name="settings[settingsOAuthConsumerSecret]" >
      </td>
    </tr>
    
    <tr>
      <th><%=t(:label_webhook_token)%></th>
      <td>
        <input 
          type="text" 
          style="width:350px" 
          id="settingsWebhookToken"
          value="<%= settings['settingsWebhookToken'] %>"
          name="settings[settingsWebhookToken]" >
      </td>
    </tr>

     <tr>
       <th><%=t(:label_oauth_expires)%></th>
       <td><%= if Qbo.exists? then Qbo.first.expire end %>
     </tr>

  </tbody>
</table>

<br/>
<%=t(:label_oauth_note)%>
<br/>
<br/>

<!-- this will display a button that the user clicks to start the flow -->
<ipp:connectToIntuit></ipp:connectToIntuit>

<br/>
<br/>

<div>
    <b><%=t(:label_customer_count)%>:</b> <%= Customer.count%>
    </div>
      
    <div>
        <b><%=t(:label_employee_count)%>:</b> <%= Employee.count %>
    </div>
    
    <div>
        <b><%=t(:label_invoice_count)%>:</b> <%= Invoice.count %>
    </div>
    
    <div>
        <b><%=t(:label_estimate_count)%>:</b> <%= Estimate.count %>
    </div>
      
    <br/>
    
    <div>
        <b><%=t(:label_last_sync)%> </b> <%= Qbo.last_sync if Qbo.exists? %> <%= link_to t(:label_sync_now), qbo_sync_path %>
</div>
