import React, { useState } from "react"; import { Card } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Info, GitBranch, FolderTree, Package, Star, Building2, User, ChevronDown, ChevronUp, Globe, Lock, Shield } from "lucide-react"; import { Separator } from "@/components/ui/separator"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible"; import type { GiteaOrgVisibility } from "@/types/config"; export type MirrorStrategy = "preserve" | "single-org" | "flat-user"; interface OrganizationStrategyProps { strategy: MirrorStrategy; destinationOrg?: string; starredReposOrg?: string; visibility: GiteaOrgVisibility; onStrategyChange: (strategy: MirrorStrategy) => void; onDestinationOrgChange: (org: string) => void; onStarredReposOrgChange: (org: string) => void; onVisibilityChange: (visibility: GiteaOrgVisibility) => void; githubUsername?: string; giteaUsername?: string; } const strategyConfig = { preserve: { title: "Mirror GitHub Structure", icon: FolderTree, description: "Keep the same organization structure as GitHub", color: "text-blue-600 dark:text-blue-400", bgColor: "bg-blue-50 dark:bg-blue-950/20", borderColor: "border-blue-200 dark:border-blue-900", details: [ "Personal repos → Your Gitea username", "Org repos → Same org name in Gitea", "Team structure preserved" ] }, "single-org": { title: "Consolidate to One Org", icon: Building2, description: "Mirror all repositories into a single organization", color: "text-purple-600 dark:text-purple-400", bgColor: "bg-purple-50 dark:bg-purple-950/20", borderColor: "border-purple-200 dark:border-purple-900", details: [ "All repos in one place", "Simplified management", "Custom organization name" ] }, "flat-user": { title: "Flat User Structure", icon: User, description: "Mirror all repositories under your user account", color: "text-green-600 dark:text-green-400", bgColor: "bg-green-50 dark:bg-green-950/20", borderColor: "border-green-200 dark:border-green-900", details: [ "All repos under your username", "No organizations needed", "Simple and personal" ] } }; const StrategyVisualizer: React.FC<{ strategy: MirrorStrategy; destinationOrg?: string; starredReposOrg?: string; githubUsername?: string; giteaUsername?: string; }> = ({ strategy, destinationOrg, starredReposOrg, githubUsername, giteaUsername }) => { const [isOpen, setIsOpen] = useState(false); const displayGithubUsername = githubUsername || ""; const displayGiteaUsername = giteaUsername || ""; const isGithubPlaceholder = !githubUsername; const isGiteaPlaceholder = !giteaUsername; const renderPreserveStructure = () => (
GitHub
{displayGithubUsername}/my-repo
my-org/team-repo
awesome/starred-repo
Gitea
{displayGiteaUsername}/my-repo
my-org/team-repo
{starredReposOrg || "starred"}/starred-repo
); const renderSingleOrg = () => (
GitHub
{displayGithubUsername}/my-repo
my-org/team-repo
awesome/starred-repo
Gitea
{destinationOrg || "github-mirrors"}/my-repo
{destinationOrg || "github-mirrors"}/team-repo
{starredReposOrg || "starred"}/starred-repo
); const renderFlatUser = () => (
GitHub
{displayGithubUsername}/my-repo
my-org/team-repo
awesome/starred-repo
Gitea
{displayGiteaUsername}/my-repo
{displayGiteaUsername}/team-repo
{starredReposOrg || "starred"}/starred-repo
); return (

Repository Mapping Preview {isOpen ? ( ) : ( )}

{strategy === "preserve" && renderPreserveStructure()} {strategy === "single-org" && renderSingleOrg()} {strategy === "flat-user" && renderFlatUser()}
); }; export const OrganizationStrategy: React.FC = ({ strategy, destinationOrg, starredReposOrg, visibility, onStrategyChange, onDestinationOrgChange, onStarredReposOrgChange, onVisibilityChange, githubUsername, giteaUsername, }) => { const visibilityOptions = [ { value: "public" as GiteaOrgVisibility, label: "Public", icon: Globe, description: "Visible to everyone" }, { value: "private" as GiteaOrgVisibility, label: "Private", icon: Lock, description: "Visible to members only" }, { value: "limited" as GiteaOrgVisibility, label: "Limited", icon: Shield, description: "Visible to logged-in users" }, ]; return (

Organization Strategy

Choose how your repositories will be organized in Gitea

{(Object.entries(strategyConfig) as [MirrorStrategy, typeof strategyConfig.preserve][]).map(([key, config]) => { const isSelected = strategy === key; const Icon = config.icon; return (

Organization Configuration

{strategy === "single-org" ? ( <> {/* Destination Organization - Left Column */}
onDestinationOrgChange(e.target.value)} placeholder="github-mirrors" className="" />

Organization for consolidated repositories

{/* Starred Repositories Organization - Right Column */}
onStarredReposOrgChange(e.target.value)} placeholder="starred" className="" />

Keep starred repos organized separately

) : ( <> {/* Starred Repositories Organization - Left Column */}
onStarredReposOrgChange(e.target.value)} placeholder="starred" className="" />

Keep starred repos organized separately

{/* Organization Visibility - Right Column */}
{visibilityOptions.map((option) => { const Icon = option.icon; const isSelected = visibility === option.value; return ( ); })}
)}
{/* Organization Visibility - Full width when single-org is selected */} {strategy === "single-org" && (
{visibilityOptions.map((option) => { const Icon = option.icon; const isSelected = visibility === option.value; return ( ); })}
)}
); };