import LabeledField from "../../cmp/field/LabeledField.jsx";
import { AsyncAuthAjax } from "../../../controller/Ajax";
import {API} from "../../../dict/Consts";
const TestRequests = D.declare('view.page.tmp.TestRequests', () => {

  return <div style={{padding: '16px'}}>
        <h1>Testing requests</h1>


      {((response, s = new Store({id: store.get('account.userID')}))=>
        <div class='test-request-block'>
          <LabeledField bind={s.bind('id')} label={'User ID'}/>
          <button onClick={async() => {
            const result = await AsyncAuthAjax.get( API.ENDPOINTS.GET_USER( s.get( 'id' ) ) );
            response.innerText = JSON.stringify( result, null, 2 );
          }}>
            Get user
          </button>
          <div className='log-block'>{response = <div/>}</div>
      </div>)()}

    {((response)=>
      <div class='test-request-block'>
        <button onClick={async() => {
          const result = await AsyncAuthAjax.get( API.ENDPOINTS.GET_USER_NEW_CARDS() );
          response.innerText = `${result.length} new cards.
`+JSON.stringify( result.slice(0,3), null, 2 )+'\n\n   . . . . .\n\n'+
  JSON.stringify( result.slice(result.length-3), null, 2 );
        }}>
          New cards
        </button>
        <div className='log-block'>{response = <div/>}</div>
      </div>)()}



  </div>
});

TestRequests.route = new Route('/testRequests');
export default TestRequests;
export {TestRequests};