/**
 * Registration Model
 *
 *
 * To seperate all login for Registration Process
 *
 */
// import React from 'react';

import Base from '../base/base';

import { ApiUtils } from './../../lib/';

/**
 * Define fields that will be used in the dashboard
 * @returns {string}
 */
class Dashboard extends Base {
  constructor() {
    super();

    this.fields = [
      {
        field: 'name',
        caption: 'Name',
      },
      {
        field: 'amount',
        caption: 'Amount',
      },
    ];

    // this.columns = ;
  }

  /**
   * Getter for the unique identifier of the dashboard
   * @returns {string} The unique identifier of the dashboard
   */
  get id() {
    return 'id';
  }

  /**
   * Getter for the endpoint URL used to fetch dashboard data
   * @returns {string}
   */
  get getEndpoint() {
    return 'dashboard';
  }

  /**
   * Getter for the model name (used for referencing the dashboard model)
   * @returns {string}
   */
  get modelName() {
    return `dashboard`;
  }

  /**
   *  Getter for the columns configuration, where each column has a 'caption' (display label) and 'field' (data source)
   * @returns {string}
   */
  get columns() {
    return [
      {
        caption: 'Staff',
        field: 'staff.name',
        key: 'staff',
      },
      {
        caption: 'Weight',
        field: 'weight',
        key: 'weight',
      },
      {
        caption: 'Date',
        field: 'created_at',
        key: 'created_at',
      },
    ];
  }

  /**
   * Function to load dashboards based on user information
   * @param {*} user
   * @returns
   */
  loadDashboards(user) {
    let group = user.user_group;

    if (typeof user.user_group === 'string') {
    } else {
      group = user.user_group.wug_code;
    }

    return ApiUtils.get({
      url: `dashboard/get-dashboard/${group}`,
    });
  }

  /**
   * Function to load menu dashboards with a form body (POST request)
   * @param {Object} formBody - The form data to send in the request body
   * @returns {Promise} - The result of the POST request
   */
  loadMenuDashboards(formBody) {
    return ApiUtils.post({
      // baseUrl: 'http://localhost:8002/dev/',
      url: `dashboard/get-menu-dashboard`,
      formBody,
    });
  }

  /**
 * Function to execute a dashboard based on its ID (GET request)
 * @param {string} id - The ID of the dashboard to execute
 * @returns {Promise} - The result of the GET request
 */
  execDashboard(id) {
    return ApiUtils.get({
      url: 'dashboard/exec/' + id,
      hideError: true,
    });
  }

  /**
   *  Function to execute a 'pop' query based on the dashboard ID (GET request)
   * @param {string} id - The ID of the dashboard to execute
   * @returns {Promise} - The result of the GET request
   */
  execPopQuery(id) {
    return ApiUtils.get({
      url: 'dashboard/pop/' + id,
      hideError: true,
    });
  }

  /**
   * To get extra script data corresponding to mode
     @param {string} mode - The Mode of the dashboard to execute
   * @returns {Promise} - The result of the GET request
   */
  getExtraInfo = (mode) => {
    return ApiUtils.get({
      url: `core-scripts/get-script-data?mode=${mode}`,
    });
  };

  /**
 * Sends a request to get selected script data based on the provided formBody.
 *
 * @param {Object} formBody - The data to be sent in the request body.
 * @returns {Promise} - The promise that resolves with the response data from the API call.
 */
  getSelectedExtraInfo = (formBody) => {
    return ApiUtils.post({
      url: `core-scripts/get-selected-script-data`,
      formBody,
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer ' + localStorage.access_token,
      },
    });
  };
}

export default Dashboard;
