import { Typography } from '@material-ui/core';
import { GridColumns } from '@material-ui/data-grid';
import { TFunction } from 'i18next';
import { formatDate } from '../../../../Utilities/DateTime';
import { IJobInfo, IProfitability } from '../../../../../../Application/DTOs/JobsDto/JobsDto.types';
import { IUserState } from '../../../../Redux/User/type';
import { COMPANY_TYPES, USER_ROLES } from '../../../../Types/Constants';

import {
  calculateGST,
  computationWaitingTimeCharge,
  getGST,
  getTotalFee,
  getAdditionalCost,
  getProfitability
} from '../../../../Utilities/Computation';
import moment from 'moment';



const getTotal = (jobInfo: any, additional_charges: any) => {
  return (jobInfo.posted_price || 0 + additional_charges + jobInfo.commission || 0) - jobInfo.initial_price || 0
}

export const getColumns = (t: TFunction, user: IUserState): GridColumns => {

  const { SUPER_ADMIN, ADMIN_USER } = USER_ROLES

  return [
    {
      field: 'reference',
      headerName: t('Columns:reference'),
      width: 200,
    },
    {
      field: 'createdAt',
      headerName: "Date",
      width: 200,
      renderCell: (params) => {
        const job: any = params.row as any

        return (
          <Typography>
            {moment(job.createdAt).format('DD-MM-YYYY')}
          </Typography>
        )
      }
    },

    {
      field: 'company',
      headerName: "Company",
      width: 200,
      renderCell: (params) => {
        const job: any = params.row as any

 
        return (
          <Typography>
            {job.company?.name}
           
          </Typography>
        )
      }
    },
    {
      field: 'customer',
      headerName: "Customer",
      width: 200,
      renderCell: (params) => {
        const job: any = params.row as any
        
        return (
          <Typography>
            {(job?.customer?.first_name && job?.customer?.last_name) ? job?.customer?.first_name + job?.customer?.last_name : "N/A"}
          </Typography>
        )
      }
    },
    {
      field: 'transport',
      headerName: "Transporter",
      width: 300,
      renderCell: (params) => {
        const job: any = params.row as any
        
        return (
          <Typography>
            {job?.transporter?.accountcontactname ?? 'N/A'}
          </Typography>
        )
      }
    },


    {
      field: 'buy_price',
      headerName: 'Sell Price($)',
      width: 200,
    },
    {
      field: 'sell_price',
      headerName: "Buy Price($)",
      width: 200,
    },
    {
      field: 'profit',
      headerName: t('Columns:Profit Price'),
      width: 200,
      renderCell: (params) => {
        const job: any = params.row as any
        
        return (
          <Typography>
            {`$ ${job?.profit}`}
          </Typography>
        )
      }
    },
   
    {
      field: 'movementType',
      headerName: "Movement Type",
      width: 200,
    },
    {
      field: 'status',
      headerName: "Status",
      width: 200,
    },
    {
      field: 'job_classification',
      headerName: "Job Classification",
      width: 200,
    },

    
  ];
};
