import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from '@/shadcn/accordion';
import { cn } from '@/utils';
import { type VariantProps, cva } from 'class-variance-authority';
import * as React from 'react';
import styles from './BaseAccordion.module.css';

const accordionItemVariants = cva(styles.AccordionItem, {
  variants: {
    variant: {
      default: '',
      primary: styles['AccordionItem--primary'],
      secondary: styles['AccordionItem--secondary'],
    },
  },
  defaultVariants: {
    variant: 'default',
  },
});

const accordionTriggerVariants = cva(styles.AccordionTrigger, {
  variants: {
    variant: {
      default: '',
      primary: styles['AccordionTrigger--primary'],
      secondary: styles['AccordionTrigger--secondary'],
    },
  },
  defaultVariants: {
    variant: 'default',
  },
});

const accordionContentVariants = cva(styles.AccordionContent, {
  variants: {
    variant: {
      default: '',
      primary: styles['AccordionContent--primary'],
      secondary: styles['AccordionContent--secondary'],
    },
  },
  defaultVariants: {
    variant: 'default',
  },
});

const BaseAccordionItem = React.forwardRef<
  React.ElementRef<typeof AccordionItem>,
  React.ComponentPropsWithoutRef<typeof AccordionItem> &
    VariantProps<typeof accordionItemVariants>
>(({ className, variant, ...props }, ref) => (
  <AccordionItem
    ref={ref}
    className={cn(accordionItemVariants({ variant }), className)}
    {...props}
  />
));
BaseAccordionItem.displayName = 'BaseAccordionItem';

const BaseAccordionTrigger = React.forwardRef<
  React.ElementRef<typeof AccordionTrigger>,
  React.ComponentPropsWithoutRef<typeof AccordionTrigger> &
    VariantProps<typeof accordionTriggerVariants>
>(({ className, variant, ...props }, ref) => (
  <AccordionTrigger
    ref={ref}
    className={cn(accordionTriggerVariants({ variant }), className)}
    {...props}
  />
));
BaseAccordionTrigger.displayName = 'BaseAccordionTrigger';

const BaseAccordionContent = React.forwardRef<
  React.ElementRef<typeof AccordionContent>,
  React.ComponentPropsWithoutRef<typeof AccordionContent> &
    VariantProps<typeof accordionContentVariants>
>(({ className, variant, ...props }, ref) => (
  <AccordionContent
    ref={ref}
    className={cn(accordionContentVariants({ variant }), className)}
    {...props}
  />
));
BaseAccordionContent.displayName = 'BaseAccordionContent';

export {
  Accordion,
  BaseAccordionItem as AccordionItem,
  BaseAccordionTrigger as AccordionTrigger,
  BaseAccordionContent as AccordionContent,
};
