File size: 3,524 Bytes
a5871f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

'use client';

import * as React from 'react';
import { Folder as FolderIcon, Share2 } from 'lucide-react';
import { TableRow, TableCell } from '@/components/ui/table';
import type { Folder } from '@/app/api/files/route';
import { cn } from '@/lib/utils';
import { Checkbox } from './ui/checkbox';
import { Button } from './ui/button';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './ui/tooltip';
import { ShareDialog } from './share-dialog';

interface FolderItemProps extends React.HTMLAttributes<HTMLTableRowElement> {
  folder: Folder;
  onSelectFolder: (path: string) => void;
  isSelected: boolean;
  onSelectItem: (id: string, isSelected: boolean) => void;
  isSelectionActive: boolean;
  isPublicShare?: boolean;
}

export function FolderItem({ folder, onSelectFolder, isSelected, onSelectItem, isSelectionActive, isPublicShare, className, ...props }: FolderItemProps) {
  const [isShareOpen, setIsShareOpen] = React.useState(false);
  
  const handleRowClick = (e: React.MouseEvent<HTMLTableRowElement>) => {
    // Prevent row click from propagating when clicking checkbox or button
    if ((e.target as HTMLElement).closest('[role="checkbox"]') || (e.target as HTMLElement).closest('button')) {
       return;
    }
    
    if (isSelectionActive) {
      onSelectItem(folder.id, !isSelected);
    } else {
      onSelectFolder(folder.path);
    }
  }

  const handleShareClick = (e: React.MouseEvent) => {
    e.stopPropagation();
    setIsShareOpen(true);
  }

  return (
    <>
    <TableRow
      className={cn("group cursor-pointer", className, isSelected && "bg-accent/50")}
      onClick={handleRowClick}
      data-selected={isSelected}
      {...props}
    >
      <TableCell className={cn("w-[40px]", !isSelectionActive && "hidden")} onClick={(e) => e.stopPropagation()}>
          <Checkbox 
            checked={isSelected}
            onCheckedChange={(checked) => onSelectItem(folder.id, Boolean(checked))}
            aria-label={`Select folder ${folder.name}`}
          />
      </TableCell>
      <TableCell className="font-medium">
        <div className="flex items-center gap-3">
          <FolderIcon className="h-5 w-5 text-muted-foreground" />
          <div className="flex-1 flex flex-col gap-1">
              <div className="flex items-center gap-2">
                 <span>{folder.name}</span>
              </div>
              <div />
            </div>
        </div>
      </TableCell>
      <TableCell className="text-muted-foreground max-w-sm truncate">
        <p>Folder</p>
      </TableCell>
      <TableCell className="text-right">
        <div className="flex items-center justify-end gap-2 h-10">
          {!isPublicShare && (
              <TooltipProvider>
                  <Tooltip>
                    <TooltipTrigger asChild>
                      <Button variant="ghost" size="icon" onClick={handleShareClick}>
                          <Share2 className="h-4 w-4" />
                          <span className="sr-only">Share</span>
                      </Button>
                    </TooltipTrigger>
                    <TooltipContent><p>Share</p></TooltipContent>
                  </Tooltip>
              </TooltipProvider>
          )}
        </div>
      </TableCell>
    </TableRow>
    {!isPublicShare && (
      <ShareDialog
          isOpen={isShareOpen}
          onOpenChange={setIsShareOpen}
          itemName={folder.name}
          itemPath={folder.path}
          itemType="folder"
      />
     )}
    </>
  );
}