import { Field, Input, Label, Select } from '@headlessui/react'
import DT from 'datatables.net-dt'
import DataTable from 'datatables.net-react'

import { SearchIcon } from '~/components/icons/search'
import { Button } from '~/components/ui/button'
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',
    },
  ]

  return (
    <div className="relative">
      <TitleDashboard title="Konten" />
      <div className="mb-8 flex items-center gap-5 rounded-lg bg-gray-50 text-[#363636]">
        <div className="w-[400px]">
          <Field>
            <Label className="mb-2 block text-sm font-medium">Cari User</Label>
            <div className="relative">
              <Input
                type="text"
                placeholder="Cari Nama"
                className="w-full rounded-lg bg-white p-2 pr-10 pl-4 shadow focus:ring-1 focus:ring-[#2E2F7C] focus:outline-none"
              />
              <div className="absolute inset-y-0 right-0 flex items-center pr-3">
                <SearchIcon className="h-5 w-5" />
              </div>
            </div>
          </Field>
        </div>

        <div className="w-[235px]">
          <Field>
            <Label className="mb-2 block text-sm font-medium">Status</Label>
            <Select className="w-full rounded-lg bg-white p-2 shadow focus:ring-1 focus:ring-[#2E2F7C] focus:outline-none">
              <option>Pilih Status</option>
              <option>Aktif</option>
              <option>Nonaktif</option>
            </Select>
          </Field>
        </div>
      </div>
      <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}
          slots={{
            6: (value: string | number) => {
              return (
                <Button
                  as="a"
                  href={`${value}`}
                >
                  Lihat Detail
                </Button>
              )
            },
          }}
          options={{
            paging: true,
            searching: true,
            ordering: true,
            info: true,
            // scrollY: '50vh',
          }}
        ></DataTable>
      </div>
    </div>
  )
}
