import React, { Component } from 'react'
import TableExtended, { TableExtendedProps, TableExtendedState } from '@hubleto/react-ui/ext/TableExtended';
import Form{{ modelSingularForm }} from './Form{{ modelSingularForm }}';

interface Table{{ modelPluralForm }}Props extends TableExtendedProps {
  // Uncomment and modify these lines if you want to create URL-based filtering for your model
  // idCustomer?: number,
}

interface Table{{ modelPluralForm }}State extends TableExtendedState {
}

export default class Table{{ modelPluralForm }} extends TableExtended<Table{{ modelPluralForm }}Props, Table{{ modelPluralForm }}State> {
  static defaultProps = {
    ...TableExtended.defaultProps,
    formUseModalSimple: true,
    model: '{{ appNamespaceForwardSlash }}/Models/{{ model }}',
  }

  props: Table{{ modelPluralForm }}Props;
  state: Table{{ modelPluralForm }}State;

  translationContext: string = '{{ appNamespaceDoubleBackslash }}';
  translationContextInner: string = 'Components\\Table{{ modelPluralForm }}';

  constructor(props: Table{{ modelPluralForm }}Props) {
    super(props);
    this.state = this.getStateFromProps(props);
  }

  getStateFromProps(props: Table{{ modelPluralForm }}Props) {
    return {
      ...super.getStateFromProps(props),
    }
  }

  getFormModalProps(): any {
    let params = super.getFormModalProps();
    params.type = 'right wide';
    return params;
  }

  getEndpointParams(): any {
    return {
      ...super.getEndpointParams(),
      // Uncomment and modify these lines if you want to create URL-based filtering for your model
      // idCustomer: this.props.idCustomer,
    }
  }

  rowClassName(rowData: any): string {
    return '';
  }

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

  renderForm(): JSX.Element {
    let formProps = this.getFormProps();
    // formProps.customEndpointParams.idCustomer = this.props.idCustomer;
    // if (!formProps.description) formProps.description = {};
    // formProps.description.defaultValues = { id_customer: this.props.idCustomer };
    return <Form{{ modelSingularForm }} {...formProps}/>;
  }
}