"use client"; import * as React from "react"; import { SlidersHorizontalIcon } from "lucide-react"; import { useSiteAdmin } from "../context"; import { fill } from "../lib/fill"; import { WIDGET_TOUR_ANCHORS } from "../tour"; import { Badge } from "../ui/badge"; import { Card } from "../ui/card"; import { Switch } from "../ui/switch"; import { TextField } from "../ui/text-field"; import { TOOL_GROUPS, type ToolGroupId } from "./widget-tool-groups"; import { useWidgetSettings } from "./WidgetSettingsProvider"; type ToolGroup = (typeof TOOL_GROUPS)[number]; // Two columns of nearly the same height: text, content and advanced (11 // tools), then colours and navigation (10). On one column the groups of the // first come before those of the second, as on the phone's board. const COLUMNS: ToolGroupId[][] = [ ["text", "content", "advanced"], ["colors", "navigation"], ]; function ToolGroupCard({ group }: { group: ToolGroup }) { const t = useSiteAdmin().messages.widget.advanced; const { canEdit, config, patchTool } = useWidgetSettings(); const id = React.useId(); const groupDict = t.toolGroups[group.id]; // Every locale gives the same { label, description } for each tool key. const tools = groupDict.tools as Record< string, { label: string; description: string } >; const active = group.toolKeys.filter((key) => config.enabledTools[key]); return (

{groupDict.title}

{groupDict.description}

{fill(t.groupCount, { active: active.length, total: group.toolKeys.length, })}
); } /** * The third tab of the Widget page (ACC-547, board W6): which of the tools * the widget's panel offers, in the five groups of the panel, each with its * switch; and under "Sicurezza" the nonce of the script, for a site with a * Content Security Policy. */ export function WidgetToolsTab() { const t = useSiteAdmin().messages.widget; const { canEdit, config, patch } = useWidgetSettings(); const states = Object.values(config.enabledTools); return ( <>

{t.advanced.title}

{t.advanced.subtitle}

{fill(t.advanced.activeCount, { active: states.filter(Boolean).length, total: states.length, })}
{COLUMNS.map((column) => ( // `contents` below two columns: the five groups are then one list, // in the order the page gives them.
{column.map((groupId) => ( group.id === groupId)!} /> ))}
))}

{t.security.title}

{t.security.description}

patch("scriptNonce", event.target.value)} className="font-mono" fieldClassName="max-w-[32.5rem]" />
); }