import type * as React from 'react';

import { cn } from '@/lib/utils';

function Frame({
  className,
  stackedPanels = false,
  ...props
}: React.ComponentProps<'div'> & { stackedPanels?: boolean }) {
  return (
    <div
      className={cn(
        'bg-muted/50 relative flex flex-col rounded-2xl p-1',
        stackedPanels
          ? '*:has-[+[data-slot=frame-panel]]:rounded-b-none *:has-[+[data-slot=frame-panel]]:before:hidden dark:*:has-[+[data-slot=frame-panel]]:before:block *:[[data-slot=frame-panel]+[data-slot=frame-panel]]:rounded-t-none *:[[data-slot=frame-panel]+[data-slot=frame-panel]]:border-t-0 dark:*:[[data-slot=frame-panel]+[data-slot=frame-panel]]:before:hidden'
          : '*:[[data-slot=frame-panel]+[data-slot=frame-panel]]:mt-1',
        className
      )}
      data-slot='frame'
      {...props}
    />
  );
}

function FramePanel({ className, ...props }: React.ComponentProps<'div'>) {
  return (
    <div
      className={cn(
        'bg-background relative rounded-xl border bg-clip-padding p-5 shadow-xs before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-xl)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:bg-clip-border dark:before:shadow-[0_-1px_--theme(--color-white/8%)]',
        className
      )}
      data-slot='frame-panel'
      {...props}
    />
  );
}

function FrameHeader({ className, ...props }: React.ComponentProps<'header'>) {
  return (
    <header
      className={cn('flex flex-col px-5 py-4', className)}
      data-slot='frame-panel-header'
      {...props}
    />
  );
}

function FrameTitle({ className, ...props }: React.ComponentProps<'div'>) {
  return (
    <div
      className={cn('text-sm font-semibold', className)}
      data-slot='frame-panel-title'
      {...props}
    />
  );
}

function FrameDescription({ className, ...props }: React.ComponentProps<'div'>) {
  return (
    <div
      className={cn('text-muted-foreground text-sm', className)}
      data-slot='frame-panel-description'
      {...props}
    />
  );
}

function FrameFooter({ className, ...props }: React.ComponentProps<'footer'>) {
  return (
    <footer
      className={cn('flex flex-col gap-1 px-5 py-4', className)}
      data-slot='frame-panel-footer'
      {...props}
    />
  );
}

export { Frame, FramePanel, FrameHeader, FrameTitle, FrameDescription, FrameFooter };
