{"version":3,"file":"BackBottom.mjs","names":[],"sources":["../../../src/chat/BackBottom/BackBottom.tsx"],"sourcesContent":["'use client';\n\nimport { useScroll } from 'ahooks';\nimport { cx } from 'antd-style';\nimport { ListEnd } from 'lucide-react';\nimport { memo, type MouseEventHandler, useEffect, useRef, useState } from 'react';\n\nimport Button from '@/Button';\n\nimport { styles } from './style';\nimport { type BackBottomProps } from './type';\n\nconst BackBottom = memo<BackBottomProps>(\n  ({ visibilityHeight = 240, target, onClick, style, className, text }) => {\n    const [visible, setVisible] = useState<boolean>(false);\n    const ref = useRef<HTMLButtonElement>(null);\n    const current = (target as any)?.current;\n    const scrollHeight = current?.scrollHeight || 0;\n    const clientHeight = current?.clientHeight || 0;\n    const scroll = useScroll(target);\n\n    useEffect(() => {\n      if (scroll?.top) {\n        setVisible(scroll?.top + clientHeight + visibilityHeight < scrollHeight);\n      }\n    }, [scrollHeight, scroll, visibilityHeight]);\n\n    const scrollToBottom: MouseEventHandler<HTMLDivElement> = (e) => {\n      (target as any)?.current?.scrollTo({ behavior: 'smooth', left: 0, top: scrollHeight });\n      onClick?.(e);\n    };\n\n    return (\n      <Button\n        glass\n        className={cx(visible ? styles.visible : styles.hidden, className)}\n        icon={ListEnd}\n        ref={ref}\n        shape={'round'}\n        size={'small'}\n        style={style}\n        variant={'filled'}\n        onClick={scrollToBottom}\n      >\n        {text || 'Back to bottom'}\n      </Button>\n    );\n  },\n);\n\nBackBottom.displayName = 'BackBottom';\n\nexport default BackBottom;\n"],"mappings":";;;;;;;;;AAYA,MAAM,aAAa,MAChB,EAAE,mBAAmB,KAAK,QAAQ,SAAS,OAAO,WAAW,WAAW;CACvE,MAAM,CAAC,SAAS,cAAc,SAAkB,MAAM;CACtD,MAAM,MAAM,OAA0B,KAAK;CAC3C,MAAM,UAAW,QAAgB;CACjC,MAAM,eAAe,SAAS,gBAAgB;CAC9C,MAAM,eAAe,SAAS,gBAAgB;CAC9C,MAAM,SAAS,UAAU,OAAO;AAEhC,iBAAgB;AACd,MAAI,QAAQ,IACV,YAAW,QAAQ,MAAM,eAAe,mBAAmB,aAAa;IAEzE;EAAC;EAAc;EAAQ;EAAiB,CAAC;CAE5C,MAAM,kBAAqD,MAAM;AAC9D,UAAgB,SAAS,SAAS;GAAE,UAAU;GAAU,MAAM;GAAG,KAAK;GAAc,CAAC;AACtF,YAAU,EAAE;;AAGd,QACE,oBAAC,QAAD;EACE,OAAA;EACA,WAAW,GAAG,UAAU,OAAO,UAAU,OAAO,QAAQ,UAAU;EAClE,MAAM;EACD;EACL,OAAO;EACP,MAAM;EACC;EACP,SAAS;EACT,SAAS;YAER,QAAQ;EACF,CAAA;EAGd;AAED,WAAW,cAAc"}