"use client"

import { useState } from "react"
import { ChevronsUpDown } from "lucide-react"
import { ComponentContainer } from "@/components/ui/component-container"
import { SectionHeading } from "@/components/ui/section-heading"
import { Button } from "@/components/ui/button"
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"

export function CollapsibleSection() {
  const [isOpen, setIsOpen] = useState(false)

  return (
    <div className="space-y-8">
      <SectionHeading title="Collapsible" description="An interactive component that expands/collapses a panel." />

      <ComponentContainer
        title="Basic Collapsible"
        description="A simple collapsible component with a trigger and content."
        code={`import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible"
import { Button } from "@/components/ui/button"
import { ChevronsUpDown } from 'lucide-react'
import { useState } from "react"

export function CollapsibleDemo() {
  const [isOpen, setIsOpen] = useState(false)
  
  return (
    <Collapsible
      open={isOpen}
      onOpenChange={setIsOpen}
      className="w-full max-w-md"
    >
      <div className="flex items-center justify-between space-x-4 px-4">
        <h4 className="text-sm font-semibold">
          @peduarte starred 3 repositories
        </h4>
        <CollapsibleTrigger asChild>
          <Button variant="ghost" size="sm">
            <ChevronsUpDown className="h-4 w-4" />
            <span className="sr-only">Toggle</span>
          </Button>
        </CollapsibleTrigger>
      </div>
      <div className="rounded-md border px-4 py-2 font-mono text-sm mt-2">
        @radix-ui/primitives
      </div>
      <CollapsibleContent className="space-y-2 mt-2">
        <div className="rounded-md border px-4 py-2 font-mono text-sm">
          @radix-ui/colors
        </div>
        <div className="rounded-md border px-4 py-2 font-mono text-sm">
          @stitches/react
        </div>
      </CollapsibleContent>
    </Collapsible>
  )
}`}
      >
        <div className="flex items-center justify-center p-6">
          <Collapsible open={isOpen} onOpenChange={setIsOpen} className="w-full max-w-md">
            <div className="flex items-center justify-between space-x-4 px-4">
              <h4 className="text-sm font-semibold">@peduarte starred 3 repositories</h4>
              <CollapsibleTrigger asChild>
                <Button variant="ghost" size="sm">
                  <ChevronsUpDown className="h-4 w-4" />
                  <span className="sr-only">Toggle</span>
                </Button>
              </CollapsibleTrigger>
            </div>
            <div className="rounded-md border px-4 py-2 font-mono text-sm mt-2">@radix-ui/primitives</div>
            <CollapsibleContent className="space-y-2 mt-2">
              <div className="rounded-md border px-4 py-2 font-mono text-sm">@radix-ui/colors</div>
              <div className="rounded-md border px-4 py-2 font-mono text-sm">@stitches/react</div>
            </CollapsibleContent>
          </Collapsible>
        </div>
      </ComponentContainer>
    </div>
  )
}
