import DT from 'datatables.net-dt'
import DataTable from 'datatables.net-react'

import { TitleDashboard } from '~/components/ui/title-dashboard'

import { CONTENTS } from './data'

export const ContentsPage = () => {
  DataTable.use(DT)
  const columns = [
    { title: 'No', data: 'id' },
    { title: 'Tanggal Kontent', data: 'createdAt' },
    { title: 'Nama Penulis', data: 'author' },
    { title: 'Judul', data: 'title' },
    { title: 'Kategori', data: 'category' },
    {
      title: 'Tags',
      data: 'tags',
      render: (value: string) => {
        return value === 'Normal'
          ? `<span class="bg-[#F5F5F5] text-[#4C5CA0] px-2 py-1 rounded-md">${value}</span>`
          : `<span class="bg-[#FFFCAF] px-2 py-1 rounded-md">${value}</span>`
      },
    },
    {
      title: 'Action',
      data: 'id',
      render: () => {
        return '<button class="bg-[#2E2F7C] text-white px-2 py-1 rounded-md">Lihat Detail</button>'
      },
    },
  ]

  return (
    <div className="relative">
      <TitleDashboard title="Konten" />
      <div className="rounded-lg bg-white p-6 shadow-md">
        <h3 className="py-1 font-semibold text-[#4C5CA0]">Daftar Content</h3>
        <DataTable
          className="cell-border"
          data={CONTENTS}
          columns={columns}
          options={{
            paging: true,
            searching: true,
            ordering: true,
            info: true,
            // scrollY: '50vh',
          }}
        ></DataTable>
      </div>
    </div>
  )
}
