"use client"

import { PageHeader } from "@/components/page-header"
import { DataTable } from "@/components/data-table"
import { domains } from "@/lib/data"
import { Button } from "@/components/ui/button"
import { UploadIcon, DownloadIcon, PlusIcon, FilterIcon } from "lucide-react"

export default function DomainsPage() {
  return (
    <div className="flex flex-col h-full">
      <PageHeader
        crumbs={[{ label: "Данные" }, { label: "Домены" }]}
        actions={
          <>
            <Button variant="outline" size="sm"><UploadIcon className="size-4" />Импорт</Button>
            <Button variant="outline" size="sm"><DownloadIcon className="size-4" />Экспорт</Button>
            <Button size="sm"><PlusIcon className="size-4" />Добавить домен</Button>
          </>
        }
      />
      <div className="flex-1 overflow-y-auto p-6">
        <div className="flex flex-col gap-4">
          <div>
            <h1 className="text-2xl font-semibold tracking-tight">Домены</h1>
            <p className="text-sm text-muted-foreground mt-1">
              Отслеживаемые домены для BGP-фильтрации — синхронизируются в address-list MikroTik
            </p>
          </div>
          <DataTable
            data={domains}
            searchPlaceholder="Поиск по домену…"
            searchKeys={["domain", "asn", "filter"]}
            columns={[
              {
                key: "domain",
                label: "Домен",
                render: (d) => <span className="font-medium">{d.domain}</span>,
              },
              {
                key: "resolvedIp",
                label: "Resolved IP",
                render: (d) => <span className="font-mono text-xs text-muted-foreground">{d.resolvedIp}</span>,
              },
              {
                key: "asn",
                label: "ASN",
                render: (d) => <span className="font-mono text-xs">{d.asn}</span>,
              },
              {
                key: "purpose",
                label: "Назначение",
                render: (d) => (
                  <span className="text-xs border border-border rounded px-2 py-0.5">{d.purpose}</span>
                ),
              },
              {
                key: "filter",
                label: "Фильтр",
                render: (d) => (
                  <span className="inline-flex items-center gap-1 text-xs bg-muted rounded px-2 py-0.5">
                    <FilterIcon className="size-3 text-muted-foreground" />{d.filter}
                  </span>
                ),
              },
              {
                key: "updated",
                label: "Обновлён",
                render: (d) => <span className="text-xs text-muted-foreground">{d.updated}</span>,
              },
              {
                key: "enabled",
                label: "Статус",
                render: (d) => (
                  <span className={`text-xs font-medium ${d.enabled ? "text-emerald-600" : "text-muted-foreground"}`}>
                    {d.enabled ? "Активен" : "Отключён"}
                  </span>
                ),
              },
            ]}
          />
        </div>
      </div>
    </div>
  )
}
