import React, { useMemo } from 'react';

import { createContextSelector } from '../utils/react';

export type AccordionContextValues = {
  bordered: boolean;
};

const [AccordionContext, useAccordionContext] =
  createContextSelector<AccordionContextValues>({
    bordered: false,
  });

export interface AccordionProviderProps {
  bordered?: boolean;
  children: React.ReactNode;
}

function AccordionProvider({
  bordered = false,
  children,
}: AccordionProviderProps) {
  const contextValue = useMemo(() => ({ bordered }), [bordered]);

  return (
    <AccordionContext.Provider value={contextValue}>
      {children}
    </AccordionContext.Provider>
  );
}

export { AccordionProvider, useAccordionContext };
