'use client'

import { type ColumnDef } from '@tanstack/react-table'

import { Abbr } from '@repo/ui/components/abbr'
import { Avatar, AvatarFallback } from '@repo/ui/components/ui/avatar'
import { initials } from '@repo/ui/lib/utils'
import {
  DataTableColumnCpfCnpj,
  DataTableColumnDatetime,
  DataTableColumnHeaderSelect,
  DataTableColumnSelect
} from '@repo/ui/components/data-table'
import type { Org } from '@repo/ui/routes/orgs/data'

export type { Org }

export const columns: ColumnDef<Org>[] = [
  {
    id: 'select',
    header: DataTableColumnHeaderSelect,
    cell: DataTableColumnSelect
  },
  {
    header: 'Empresa',
    cell: ({ row }) => {
      const { name, email } = row.original

      return (
        <div className="flex gap-2.5 items-center">
          <Avatar className="size-10 hidden lg:block">
            <AvatarFallback>{initials(name)}</AvatarFallback>
          </Avatar>

          <ul>
            <li className="font-bold">
              <Abbr>{name}</Abbr>
            </li>
            <li className="text-muted-foreground text-sm">
              <Abbr>{email}</Abbr>
            </li>
          </ul>
        </div>
      )
    }
  },
  {
    accessorKey: 'cnpj',
    header: 'CNPJ',
    cell: DataTableColumnCpfCnpj
  },
  {
    accessorKey: 'createDate',
    header: 'Cadastrado em',
    cell: DataTableColumnDatetime
  }
]
