"use client"; import type { Column, ColumnPinningState, RowSelectionState, } from "@tanstack/react-table"; import { type ColumnDef, type ColumnFiltersState, type FilterFn, flexRender, getCoreRowModel, getFilteredRowModel, getSortedRowModel, type SortingState, useReactTable, } from "@tanstack/react-table"; import { ArrowDown, ArrowUp, ArrowUpDown, Clock, DollarSign, Factory, Globe, Link, Linkedin, SlidersHorizontal, Tag, Users, X, } from "lucide-react"; import React, { useMemo, useState } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { cn } from "@/lib/utils"; interface Company { name: string; logo: string; categories: string[]; linkedin: string; linkedinUsername: string; lastInteraction: string; connectionStrength: string; twitterFollowers: number; employees: number; website: string; industry: string; revenue: string; } const defaultCompanies: Company[] = [ { name: "Figma", logo: "/block-media/shadcnblocks/block/logos/figma-icon.svg", categories: ["طراحی", "SaaS"], linkedin: "https://linkedin.com/company/figma", linkedinUsername: "figma", lastInteraction: "۲ روز پیش", connectionStrength: "قوی", twitterFollowers: 524000, employees: 1200, website: "https://figma.com", industry: "ابزار طراحی", revenue: "بیش از ۵۰۰ میلیون دلار", }, { name: "Vercel", logo: "/block-media/shadcnblocks/block/logos/vercel-icon.svg", categories: ["ابر", "DevOps"], linkedin: "https://linkedin.com/company/vercel", linkedinUsername: "vercel", lastInteraction: "۱ هفته پیش", connectionStrength: "متوسط", twitterFollowers: 312000, employees: 450, website: "https://vercel.com", industry: "زیرساخت ابری", revenue: "بیش از ۱۰۰ میلیون دلار", }, { name: "Supabase", logo: "/block-media/shadcnblocks/block/logos/supabase.svg", categories: ["پایگاه داده", "بک‌اند"], linkedin: "https://linkedin.com/company/supabase", linkedinUsername: "supabase", lastInteraction: "۳ روز پیش", connectionStrength: "قوی", twitterFollowers: 156000, employees: 180, website: "https://supabase.com", industry: "پایگاه داده", revenue: "بیش از ۵۰ میلیون دلار", }, { name: "GitHub", logo: "/block-media/shadcnblocks/block/logos/github-icon.svg", categories: ["ابزار توسعه", "همکاری"], linkedin: "https://linkedin.com/company/github", linkedinUsername: "github", lastInteraction: "دیروز", connectionStrength: "قوی", twitterFollowers: 2400000, employees: 3000, website: "https://github.com", industry: "ابزار توسعه", revenue: "بیش از ۱ میلیارد دلار", }, { name: "Notion", logo: "/block-media/shadcnblocks/block/logos/notion-icon.svg", categories: ["بهره‌وری", "SaaS"], linkedin: "https://linkedin.com/company/notion", linkedinUsername: "notionhq", lastInteraction: "۵ روز پیش", connectionStrength: "متوسط", twitterFollowers: 890000, employees: 500, website: "https://notion.so", industry: "بهره‌وری", revenue: "بیش از ۲۵۰ میلیون دلار", }, ]; interface IconHeaderProps { icon: React.ReactNode; label: string; } const IconHeader = ({ icon, label }: IconHeaderProps) => { return (
{icon} {label}
); }; interface HeaderWithSortingProps { column: Column; label: string; icon?: React.ReactNode; } const HeaderWithSorting = ({ column, label, icon }: HeaderWithSortingProps) => { const sorted = column.getIsSorted(); return ( ); }; interface FilterCheckboxListProps { options: string[]; selectedValues: string[]; header: string; onFilterChange: (updatedValues: string[] | undefined) => void; } const FilterCheckboxList = ({ options, selectedValues, header, onFilterChange, }: FilterCheckboxListProps) => { return (
{options.map((option) => (
{ const updated = checked ? [...selectedValues, option] : selectedValues.filter((v) => v !== option); onFilterChange(updated.length ? updated : undefined); }} />
))}
); }; const categoryIncludesFilter: FilterFn = ( row, columnId, filterValue, ) => { const value = row.getValue(columnId); const filterArray = filterValue as string[]; if (!filterArray || filterArray.length === 0) return true; return filterArray.some((filter) => value.includes(filter)); }; const industryIncludesFilter: FilterFn = ( row, columnId, filterValue, ) => { const value = row.getValue(columnId); const filterArray = filterValue as string[]; if (!filterArray || filterArray.length === 0) return true; return filterArray.includes(value); }; const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="انتخاب همه" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="انتخاب ردیف" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: "name", header: ({ column }) => ( ), cell: ({ row }) => (
{row.original.name} {row.original.name}
), footer: ({ table }) => { const count = table.getRowCount(); return (

{count.toLocaleString("fa-IR")}{" "} شرکت

); }, }, { accessorKey: "categories", header: () => } label="دسته‌بندی‌ها" />, cell: ({ row }) => (
{row.original.categories.map((category) => ( {category} ))}
), filterFn: categoryIncludesFilter, }, { accessorKey: "industry", header: () => } label="صنعت" />, filterFn: industryIncludesFilter, }, { accessorKey: "employees", header: ({ column }) => ( } /> ), cell: ({ row }) => ( {row.original.employees.toLocaleString("fa-IR")} ), }, { accessorKey: "revenue", header: () => } label="درآمد" />, cell: ({ row }) => {row.original.revenue}, }, { accessorKey: "connectionStrength", header: ({ column }) => ( } /> ), cell: ({ row }) => { const strength = row.original.connectionStrength; const variant = strength === "قوی" ? "default" : strength === "متوسط" ? "secondary" : "outline"; return (
{strength}
); }, }, { accessorKey: "lastInteraction", header: () => } label="آخرین ارتباط" />, }, { accessorKey: "twitterFollowers", header: ({ column }) => ( } /> ), cell: ({ row }) => ( {row.original.twitterFollowers.toLocaleString("fa-IR")} ), }, { accessorKey: "linkedin", header: ({ column }) => ( } /> ), cell: ({ row }) => ( {row.original.linkedinUsername} ), }, { accessorKey: "website", header: ({ column }) => ( } /> ), cell: ({ row }) => ( {row.original.website.replace("https://", "")} ), }, ]; interface CompaniesList1Props { className?: string; title?: string; data?: Company[]; } const CompaniesList1 = ({ className, title = "شرکت‌ها", data = defaultCompanies, }: CompaniesList1Props) => { const [sorting, setSorting] = useState([]); const [rowSelection, setRowSelection] = useState({}); const [globalFilter, setGlobalFilter] = useState(""); const [columnFilters, setColumnFilters] = useState([]); const [columnPinning, setColumnPinning] = useState({ left: ["select"], }); const uniqueCategories = useMemo(() => { const categories = new Set(); data.forEach((company) => { company.categories.forEach((cat) => categories.add(cat)); }); return Array.from(categories).sort(); }, [data]); const uniqueIndustries = useMemo(() => { const industries = new Set(); data.forEach((company) => { industries.add(company.industry); }); return Array.from(industries).sort(); }, [data]); const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), getFilteredRowModel: getFilteredRowModel(), getSortedRowModel: getSortedRowModel(), onColumnFiltersChange: setColumnFilters, onColumnPinningChange: setColumnPinning, onGlobalFilterChange: setGlobalFilter, onRowSelectionChange: setRowSelection, onSortingChange: setSorting, state: { columnFilters, columnPinning, globalFilter, sorting, rowSelection, }, }); const categoryFilter = (table.getColumn("categories")?.getFilterValue() as string[]) ?? []; const industryFilter = (table.getColumn("industry")?.getFilterValue() as string[]) ?? []; return (

{title}

setGlobalFilter(e.target.value)} className="w-full md:w-56" />
table.getColumn("categories")?.setFilterValue(values) } />
table.getColumn("industry")?.setFilterValue(values) } />
{categoryFilter.length + industryFilter.length > 0 && ( )}
{sorting.length > 0 && ( )}
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( {flexRender( header.column.columnDef.header, header.getContext(), )} ))} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender( cell.column.columnDef.cell, cell.getContext(), )} ))} )) ) : ( هیچ شرکتی با این معیارها یافت نشد. )} {table.getFooterGroups().map((footerGroup) => ( {footerGroup.headers.map((header) => ( {header.isPlaceholder ? (
) : ( flexRender( header.column.columnDef.footer, header.getContext(), ) )} ))} ))}
); }; export { CompaniesList1 };