import useTranslation from 'next-translate/useTranslation';
import React, { FC, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import CRUDBuilder from '../../../../utils/CRUDBuilder/CRUDBuilder';
import { ItemType } from '../../../../utils/CRUDBuilder/types';

import { DeleteBlogAsync, FetchBlogsAsync, InsertBlogAsync, selectBlogs, selectBlogsStatus, UpdateBlogAsync } from '../../../../redux/blog';
import { GetServerSideProps } from 'next';
import { DashboardAuthenticated } from '../../../../utils/helpers/dashboard-authenticated';


export const columnsBlogs: ItemType[] = [
    {
        columnType: {
            title: 'ID',
            dataIndex: 'id',
            fixed: 'left',
            width: 100,
        },
        type: 'primary-key'
    },
    {
        columnType: {
            title: 'Article Title',
            dataIndex: 'article_title',
            width: 200,
        },
        type: 'text',
        trans: true
    },
    {
        columnType: {
            title: 'Article Body',
            dataIndex: 'article_body',
            width: 400,
        },
        type: 'html-editor',
        trans: true
    },
    {
        columnType: {
            title: 'Image',
            dataIndex: 'image_path',
            width: 300,
        },
        type: 'image',
    },
];

const ManageBlogs: FC = () => {
    return <></>

    const blogs = useSelector(selectBlogs)
    const status = useSelector(selectBlogsStatus)

    const { lang } = useTranslation()

    const dispatch = useDispatch()

    useEffect(() => {
        dispatch(FetchBlogsAsync())
    }, [dispatch])


    return (
        <CRUDBuilder
            lang={lang === 'en' ? 'en' : 'ar'}
            items={blogs}
            loading={status === 'loading'}
            AddAsync={(el) => InsertBlogAsync({ blog: el.item })}
            UpdateAsync={(el) => UpdateBlogAsync({ id: el.id, blog: el.item })}
            DeleteAsync={(el) => DeleteBlogAsync({ id: el.id })}
            itemsHeader={columnsBlogs}
        />
    )
}
export default ManageBlogs;

export const getServerSideProps: GetServerSideProps = DashboardAuthenticated;