"use client"

import { useIntl } from "react-intl"

import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"

import Button from "@/components/TempDesignSystem/Button"

import { showMoreButtonVariants } from "./variants"

import styles from "./showMoreButton.module.css"

import type { ShowMoreButtonProps } from "./showMoreButton"

export default function ShowMoreButton({
  className,
  buttonIntent,
  intent,
  disabled,
  showLess,
  textShowMore,
  textShowLess,
  loadMoreData,
}: ShowMoreButtonProps) {
  const intl = useIntl()
  const classNames = showMoreButtonVariants({
    className,
    buttonIntent,
  })

  if (!textShowMore) {
    textShowMore = intl.formatMessage({
      defaultMessage: "Show more",
    })
  }

  if (!textShowLess) {
    textShowLess = intl.formatMessage({
      defaultMessage: "Show less",
    })
  }

  return (
    <div className={`${classNames} ${showLess ? styles.showLess : ""}`}>
      <Button
        className={styles.button}
        disabled={disabled}
        onClick={loadMoreData}
        variant="icon"
        type="button"
        theme="base"
        intent={intent ?? "text"}
        fullWidth={intent ? true : false}
        size={intent && "small"}
      >
        <MaterialIcon
          icon="keyboard_arrow_down"
          className={styles.icon}
          color="CurrentColor"
        />
        {showLess ? textShowLess : textShowMore}
      </Button>
    </div>
  )
}
