"use client";
import {
  Shield,
  User,
  DollarSign,
  ClipboardList,
  CalendarIcon,
  TrendingUp,
  ArrowLeftRight,
  Link as LinkIcon,
} from "lucide-react";
import { useTranslations } from "next-intl";
export function useColumns(): ColumnDefinition[] {
  const tCommon = useTranslations("common");
  const tDashboardAdmin = useTranslations("dashboard_admin");
  return [
    {
      key: "id",
      title: tCommon("id"),
      type: "text",
      icon: Shield,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tCommon("unique_identifier_for_the_order"),
      priority: 2,
      expandedOnly: true,
    },
    {
      key: "referenceId",
      title: tCommon("reference_id"),
      type: "text",
      icon: LinkIcon,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("external_exchange_reference_id"),
      priority: 2,
      expandedOnly: true,
    },
    {
      key: "user",
      title: tCommon("user"),
      type: "compound",
      icon: User,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("trader_details"),
      render: {
        type: "compound",
        config: {
          image: {
            key: "avatar",
            fallback: "/img/placeholder.svg",
            type: "image",
            title: tCommon("avatar"),
            description: tCommon("user_avatar"),
          },
          primary: {
            key: ["firstName", "lastName"],
            title: [tCommon("first_name"), tCommon("last_name")],
            description: [tDashboardAdmin("traders_first_name"), tDashboardAdmin("traders_last_name")],
            icon: User,
          },
          secondary: {
            key: "email",
            title: tCommon("email"),
            icon: ClipboardList,
          },
        },
      },
      priority: 1,
    },
    {
      key: "symbol",
      title: tCommon("symbol"),
      type: "text",
      icon: TrendingUp,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("trading_pair_e_g_btc_usdt"),
      priority: 1,
    },
    {
      key: "type",
      title: tCommon("order_type"),
      type: "select",
      icon: ArrowLeftRight,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("market_or_limit_order"),
      options: [
        { value: "MARKET", label: tCommon("market") },
        { value: "LIMIT", label: tCommon("limit") },
      ],
      priority: 1,
    },
    {
      key: "timeInForce",
      title: tDashboardAdmin("time_in_force"),
      type: "select",
      icon: ClipboardList,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("gtc_ioc_fok_or_po"),
      options: [
        { value: "GTC", label: tDashboardAdmin("gtc") },
        { value: "IOC", label: tDashboardAdmin("ioc") },
        { value: "FOK", label: tDashboardAdmin("fok") },
        { value: "PO", label: tDashboardAdmin("po") },
      ],
      priority: 1,
      expandedOnly: true,
    },
    {
      key: "side",
      title: tCommon("side"),
      type: "select",
      icon: ArrowLeftRight,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("buy_or_sell"),
      options: [
        { value: "BUY", label: tCommon("buy") },
        { value: "SELL", label: tCommon("sell") },
      ],
      render: {
        type: "badge",
        config: {
          variant: (value: string) => {
            switch (value?.toUpperCase()) {
              case "BUY":
                return "success";
              case "SELL":
                return "danger";
              default:
                return "default";
            }
          },
        },
      },
      priority: 1,
    },
    {
      key: "price",
      title: tCommon("price"),
      type: "number",
      icon: DollarSign,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("order_price_per_unit"),
      priority: 1,
    },
    {
      key: "amount",
      title: tCommon("amount"),
      type: "number",
      icon: DollarSign,
      sortable: true,
      searchable: false,
      filterable: true,
      description: tDashboardAdmin("order_quantity"),
      priority: 1,
    },
    {
      key: "filled",
      title: tCommon("filled"),
      type: "number",
      icon: DollarSign,
      sortable: true,
      searchable: false,
      filterable: true,
      description: tDashboardAdmin("amount_filled"),
      priority: 1,
      expandedOnly: true,
    },
    {
      key: "remaining",
      title: tCommon("remaining"),
      type: "number",
      icon: DollarSign,
      sortable: true,
      searchable: false,
      filterable: true,
      description: tDashboardAdmin("amount_remaining"),
      priority: 1,
      expandedOnly: true,
    },
    {
      key: "cost",
      title: tCommon("cost"),
      type: "number",
      icon: DollarSign,
      sortable: true,
      searchable: false,
      filterable: true,
      description: tDashboardAdmin("total_cost"),
      priority: 1,
      expandedOnly: true,
    },
    {
      key: "fee",
      title: tCommon("fee"),
      type: "number",
      icon: DollarSign,
      sortable: true,
      searchable: false,
      filterable: true,
      description: tCommon("transaction_fee"),
      priority: 1,
      expandedOnly: true,
    },
    {
      key: "feeCurrency",
      title: tDashboardAdmin("fee_currency"),
      type: "text",
      icon: DollarSign,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("currency_for_the_fee"),
      priority: 1,
      expandedOnly: true,
    },
    {
      key: "status",
      title: tCommon("status"),
      type: "select",
      icon: ClipboardList,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tCommon("order_status"),
      options: [
        { value: "OPEN", label: tCommon("open") },
        { value: "CLOSED", label: tCommon("closed") },
        { value: "CANCELED", label: tDashboardAdmin("canceled") },
        { value: "EXPIRED", label: tCommon("expired") },
        { value: "REJECTED", label: tCommon("rejected") },
      ],
      render: {
        type: "badge",
        config: {
          variant: (value) => {
            const statusMap = {
              OPEN: "warning",
              CLOSED: "success",
              CANCELED: "muted",
              EXPIRED: "danger",
              REJECTED: "danger",
            };
            return statusMap[value?.toUpperCase()] || "default";
          },
        },
      },
      priority: 1,
    },
    {
      key: "createdAt",
      title: tCommon("created_at"),
      type: "date",
      icon: CalendarIcon,
      sortable: true,
      searchable: true,
      filterable: true,
      description: tDashboardAdmin("order_creation_date"),
      priority: 2,
      expandedOnly: true,
      render: { type: "date", format: "PPP", fullDate: true },
    },
  ];
}
