// @ts-expect-error -- ?island not typed
import LanguageSwitcherIsland from './islands/LanguageSwitcherIsland.js?island';
import type { LanguageSwitcherProps } from './types.js';
import { Island, useLanguageVariants } from '@hubspot/cms-components';
import ContentFields from './ContentFields.js';
import StyleFields from './StyleFields.js';

const LanguageSwitcherComponent = ({
  translations: translationsProp,
  ...rest
}: LanguageSwitcherProps) => {
  const languageVariants = useLanguageVariants();
  const translations = translationsProp ?? languageVariants;

  return (
    <Island
      module={LanguageSwitcherIsland}
      translations={translations}
      {...rest}
    />
  );
};

type LanguageSwitcherComponentType = typeof LanguageSwitcherComponent & {
  ContentFields: typeof ContentFields;
  StyleFields: typeof StyleFields;
};

const LanguageSwitcher =
  LanguageSwitcherComponent as LanguageSwitcherComponentType;
LanguageSwitcher.ContentFields = ContentFields;
LanguageSwitcher.StyleFields = StyleFields;

export default LanguageSwitcher;
