// @ts-nocheck
import React from 'react';
import Base from '../base/base';

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

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

import UserDetail from './components/user-detail/user-detail';

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

import UserList from './components/user-list/user-list';

import UserAdd from './components/user-add/user-add';

class Users extends Base {

    constructor() {

        super();

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

    /**
     * Link for redirection
     */
    get link() {
        return this.name.toLowerCase();
    }


    get getEndpoint() {
        return 'users';
    }

    get path() {
        return `users`;
    }

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

    get modelName() {
        return `user`;
    }

    get route() {
        return 'users';
    }

    /**
     *
     */
    get columns() {
        return [
            {
                caption: 'Name',
                field: 'name',
                key: 'name',
            },

            {
                caption: 'Email',
                field: 'email',
                key: 'email',
            },

            // {
            //     // field: '',
            //     title: 'Detail',
            //     render: record => {
            //         return (
            //             <ExtraInfoDetail icon={true} modeValue='UD' icon='Button' title='User Details' {...record} />

            //         );
            //     },
            // }

            // {
            //     caption: 'Url',
            //     field: 'url',
            //     key: 'url',
            // },

            // {
            //     caption: 'Route',
            //     field: 'route',
            //     key: 'route',
            // },

            // {
            //     caption: 'Doc Url',
            //     field: 'documentation_url',
            //     key: 'documentation_url',
            // },

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

    ListComponent = UserList;

    DetailComponent = UserDetail;

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

    login = (formBody) => {

        return ApiUtils.post({ url: 'auth/login', formBody, baseUrl: process.env.REACT_APP_baseurl })
    }


    /**
      *
      * @param {*} values
      * @param {*} user
      * @returns
      */
    update = ({ id, formBody, user }) => {

        return ApiUtils.put({ url: this.endpoint + '/' + id, formBody });
    };


    authStatus = () => {

        return ApiUtils.get({ url: 'auth/whoami', baseUrl: process.env.REACT_APP_baseurl })
    }

    logout = () => {

        return ApiUtils.put({ url: 'auth/logout', baseUrl: process.env.REACT_APP_baseurl })
    }

    /**
    * Cutsom Api for creating user 
    * 
    * @param {*} values 
    * @returns 
    */
    create = (formBody) => {

        return ApiUtils.post({ url: `users/create-user`, formBody });
    }
    /**
     * Get Ldap users
     * @returns 
     */
    getLdapUsers = () => {

        return ApiUtils.get({ url: 'auth/ldap-users', baseUrl: process.env.REACT_APP_baseurl })
    }

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

}

export default Users;
