// @ts-nocheck
import React from 'react';
import { BaseAPI } from '..';

import RoleList from './components/role-list/role-list';
import RoleAdd from './components/role-add/role-add';
import { ExtraInfoDetail } from './../../lib/';
import { DateUtils } from './../../lib/';
import { ApiUtils } from './../../lib/';

class RolesAPI extends BaseAPI {

    constructor() {

        super();

        this.fields = [
            {
                field: 'name',
                caption: 'Name',
            },

            {
                field: 'description',
                caption: 'Description',
            },

            {
                field: 'path',
                caption: 'Path',
            },
        ];

    }

    relativeAdd() {
        return true;
    }


    get getEndpoint() {
        return 'core-roles';
    }

    get path() {
        return `roles`;
    }

    get getName() {
        return this.modelName + `s`;
    }

    get modelName() {
        return `core-role`;
    }

    get columns() {
        return [

            //     {
            //     caption: 'Type',
            //     field: 'type',
            //     key: 'type',
            // },

            {
                caption: 'Name',
                field: 'name',
                key: 'name',
            },

            {
                caption: 'Identifier',
                field: 'identifier',
                key: 'identifier',
            },

            // {
            //     caption: 'Mode',
            //     field: 'mode',
            //     key: 'mode',
            // },

            // {
            //     caption: 'Created By',
            //     field: 'created_by',
            //     key: 'created_by',
            // },

            {
                caption: 'Created at',
                field: 'created_at',
                key: 'created_at',
                render: (ele) => {
                    return ele.created_at ? DateUtils.formatDate(ele.created_at) : null
                },
            },

            // {
            //     // field: '',
            //     title: 'Eye',
            //     render: record => {
            //         return (
            //             <ExtraInfoDetail icon={true} modeValue='RD' title='Role Details' {...record} />

            //         );
            //     },
            // }
        ];
    }

    ListComponent = RoleList;

    ModalAddComponent = (props) => <RoleAdd model={this} {...props} />;


    /**
     * load the detail of role
     *
     * @param {*} menu
     * @returns
     */
    getDetail = (id) => {
        return this.getRecord(id).then((result) => {
            return result;
        });
    };

    /**
     * load the list of role
     *
     * @param {*} menu
     * @returns
     */
    getRoles = (config) => {

        // return this.getData({ path: `menus/get-menus`, queries: queries}).then((result) => {
        //     return result;
        // });

        return this.get({ url: `admin/role`, config: config }).then((result) => {
            return result;
        });

    };

     /**
    * Cutsom Api for creating user 
    * 
    * @param {*} values 
    * @returns 
    */
     createRole = (formBody) => {
        return ApiUtils.post({ url: `core-roles/create`, formBody });
    }


    /**
    * Cutsom Api for updating user 
    * 
    * @param {*} values 
    * @returns 
    */
    updateRole = ({ id, formBody }) => {
        return ApiUtils.put({ url: `core-roles/update/${id}`, formBody });
    }


    // /**
    //  * Function to load the roles
    //  *
    //  * @param {*} item
    //  * @returns
    //  */
    // loadMenus = (item) => {
    //     return this.get().then((result) => {
    //         return Promise.all(result.menus.map(this.loadDetail)).then((result) => {
    //             return { menus: result };
    //         });
    //     });
    // };

    // ModalAddComponent = 


}

export default RolesAPI;
