import { client } from '@/ui/api/client' import { ShareSecuritySettings } from '@/ui/components/share-security-settings' import { Button } from '@/ui/components/ui/button' import { Input } from '@/ui/components/ui/input' import { Label } from '@/ui/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/ui/components/ui/select' import { Switch } from '@/ui/components/ui/switch' import { copyToClipboard as copyTextToClipboard } from '@/ui/lib/clipboard' import { m } from '@/ui/paraglide/messages.js' import { ShareLinkInfo, UpdateShareLinkRequest, type FieldInfo as MetadataFieldInfo, } from '@shumai/dtos' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { ArrowDownUp, ChevronRight, Copy, ExternalLink, LayoutGrid, List, ListFilter, Palette, Shield, SortAsc, } from 'lucide-react' import React, { useState } from 'react' import { toast } from 'sonner' interface ShareSettingsSidebarProps { shareLink: ShareLinkInfo viewMode: 'card' | 'list' onViewModeChange: (mode: 'card' | 'list') => void defaultSortOrder: string | null onSortOrderChange: (sortOrder: string | null) => void } export function ShareSettingsSidebar({ shareLink, viewMode, onViewModeChange, defaultSortOrder, onSortOrderChange, }: ShareSettingsSidebarProps) { const queryClient = useQueryClient() const { data: fields } = useQuery({ queryKey: ['fields', shareLink.projectId], queryFn: async () => { const res = await client.api.projects[':projectId'].fields.$get({ param: { projectId: shareLink.projectId }, }) if (!res.ok) throw new Error(m.failed_fetch_fields()) return await res.json() }, enabled: !!shareLink.projectId, }) const $updateShare = client.api.shares[':shareId'].$put const { mutate: updateShare } = useMutation({ mutationFn: async (json: UpdateShareLinkRequest) => { const res = await $updateShare({ param: { shareId: shareLink.id }, json, }) if (!res.ok) throw new Error(m.failed_update()) return await res.json() }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['shares', shareLink.projectId] }) queryClient.invalidateQueries({ queryKey: ['share', shareLink.id] }) toast.success(m.settings_updated()) }, }) const shareUrl = `${window.location.origin}/share/${shareLink.id}` const copyToClipboard = async (text: string) => { const ok = await copyTextToClipboard(text) if (ok) { toast.success(m.copied_to_clipboard()) } } const toggleFieldVisibility = (fieldId: string) => { const current = shareLink.fieldVisibility || {} const next = { ...current, [fieldId]: !current[fieldId] } updateShare({ fieldVisibility: next }) } // Parse current sort field and order let currentSortField = 'index' let currentSortOrder = 'asc' if (defaultSortOrder) { const parts = defaultSortOrder.split(':') currentSortField = parts[0] currentSortOrder = parts[1] || 'asc' } return (

{m.link_visibility()}

updateShare({ isDisabled: !checked })} />
}> }>
}>
{(fields as MetadataFieldInfo[])?.map((field) => (
toggleFieldVisibility(field.id)} />
))}
}>
) } function SidebarAccordionItem({ title, icon, children, }: { title: string icon: React.ReactNode children?: React.ReactNode }) { const [isOpen, setIsOpen] = useState(false) return (
{isOpen && children && (
{children}
)}
) } function cn(...classes: (string | boolean | undefined | null)[]) { return classes.filter(Boolean).join(' ') }