import { forwardRef, useContext } from "react"
import { THeadProps } from "./interface"
import { css } from "@emotion/react"
import { TableContext } from "./table-context"
import { applyPinedStyle, applyResizerTableHeaderStyle } from "./style"
import { applyBoxStyle, deleteCssProps } from "../model/src"
import { useTheme } from "@mui/material"

export const Thead = forwardRef<HTMLTableSectionElement, THeadProps>(
  (props, ref) => {
    const { pinedHeader, ...otherProps } = props
    const tableContext = useContext(TableContext)
const theme = useTheme()
    return tableContext?.showHeader ? (
      <thead
        css={css(
          applyResizerTableHeaderStyle(tableContext?.enableColumnResizing),
          applyPinedStyle(pinedHeader),
          applyBoxStyle(props,theme),
        )}
        ref={ref}
        {...deleteCssProps(otherProps)}
      />
    ) : null
  },
)

Thead.displayName = "Thead"
