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

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

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


class Dashboard extends Base {
    constructor() {
        super();

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

        // this.columns = ;
    }

    get id() {
        return 'id';
    }

    get getEndpoint() {
        return 'dashboard';
    }


    get modelName() {
        return `dashboard`;
    }

    get columns() {
        return [
            {
                caption: 'Staff',
                field: 'staff.name',
                key: 'staff'
            },
            {
                caption: 'Weight',
                field: 'weight',
                key: 'weight'
            },
            {
                caption: 'Date',
                field: 'created_at',
                key: 'created_at'
            }
        ];
    }

    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}`
        });
    }

    execDashboard(id) {
        return ApiUtils.get({
            url: 'dashboard/exec/' + id,
            hideError: true
        });

    }

    execPopQuery(id) {
        return ApiUtils.get({
            url: 'dashboard/pop/' + id,
            hideError: true
        });
    }

    
    /**
      * To get extra script data corresponding to mode
      *
      * @param {*} mode
      * @returns
      */
    getExtraInfo = (mode) => {
        return ApiUtils.get({
            url: `core-scripts/get-script-data?mode=${mode}`,
        });
    };


    /**
      * To get executed data
      *
      * @param {*} mode
      * @returns
      */

    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;
