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

import ModelDetail from './components/model-detail/model-detail';

// For formatting Date
import { DateUtils } from './../../lib/';
import ModalAdd from './components/model-detail/model-add';

class Models extends Base {

    constructor() {
        super();

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

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

            {
                field: 'table_name',
                caption: 'Table Name',
            },

            {
                field: 'allowed_permissions',
                caption: 'Allowed Permissions',
            },


            {
                field: 'route_name',
                caption: 'Route Name',
            },


            {
                field: 'display_column',
                caption: 'Display Column',
            },

            {
                field: 'menu_url',
                caption: 'Menu Url',
            },

            {
                field: 'model_hash',
                caption: 'Model Hash',
            },

        ];
    }

    get getEndpoint() {
        return 'core-model-details';
    }

    get path() {
        return `models`;
    }

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

    get modelName() {
        return `model`;
    }

    get route() {
        return 'core-model-details';
    }

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

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

            // {
            //     caption: 'Path',
            //     field: 'path',
            //     key: 'path',
            // },

            // {
            //     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
                },
            },
        ];
    }

    /**
    * load all Pages
    *
    * @param {*} menu
    * @returns
    */
    getModels = () => {

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

        return this.get({ url: `core-model-details` }).then((result) => {
            return result;
        });

    }

    /**
     * Detail Component
     */
    DetailComponent = () => <ModalAdd model={this} />

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

}

export default Models;
