import React, { Component } from 'react'
import TableExtended, { TableExtendedProps, TableExtendedState } from '@hubleto/react-ui/ext/TableExtended';
import FormCashRegister, { FormCashRegisterProps } from './FormCashRegister';
import { getUrlParam } from '@hubleto/react-ui/core/Helper';
import { FormProps } from '@hubleto/react-ui/core/Form';
import request from '@hubleto/react-ui/core/Request';

interface TableCashRegistersProps extends TableExtendedProps {
}

interface TableCashRegistersState extends TableExtendedState {
  tableContactsDescription?: any,
  tableLeadsDescription?: any,
  tableDealsDescription?: any,
  tableDocumentsDescription?: any,
}

export default class TableCashRegisters extends TableExtended<TableCashRegistersProps, TableCashRegistersState> {
  static defaultProps = {
    ...TableExtended.defaultProps,
    formUseModalSimple: true,
    model: 'Hubleto/App/Community/Cashdesk/Models/CashRegister',
  }

  props: TableCashRegistersProps;
  state: TableCashRegistersState;

  translationContext: string = 'Hubleto\\App\\Community\\Cashdesk\\Loader';
  translationContextInner: string = 'Components\\TableCashRegisters';

  getFormModalProps() {
    return {
      ...super.getFormModalProps(),
      type: 'right wide'
    }
  }

  setRecordFormUrl(id: number) {
    window.history.pushState({}, "", globalThis.hubleto.config.projectUrl + '/cashdesk/cash-registers/' + (id > 0 ? id : 'add'));
  }

  renderForm(): JSX.Element {
    let formProps: FormCashRegisterProps = this.getFormProps() as FormCashRegisterProps;
    return <FormCashRegister {...formProps}/>;
  }
  
  renderTable(): JSX.Element {
    return <div className='grid grid-cols-4 gap-2'>
      {this.state.data.records.map((row, index) => {
        return <button
          onClick={() => { this.openForm(row.id); }}
          className='btn btn-square btn-transparent btn-large'
        >
          <div className='card-header text-center flex-col'>
            <div><i className='fas fa-cash-register text-4xl mb-4'></i></div>
            <div>{row.identifier}</div>
          </div>
          <div className='card-body'>
            {row.description}
          </div>
        </button>;
      })}
    </div>;
  }
}