"use client"; import { AttachmentAction as UiAttachmentAction } from "@suphark/ui/components/ui/attachment"; import { CarouselNext as UiCarouselNext, CarouselPrevious as UiCarouselPrevious, useCarousel, } from "@suphark/ui/components/ui/carousel"; import { MessageScrollerButton as UiMessageScrollerButton } from "@suphark/ui/components/ui/message-scroller"; import type { ComponentProps, ComponentType } from "react"; import { SimpleTooltip } from "./simple-tooltip"; import { useUiText } from "./ui-text"; /** * `TooltipTrigger` ส่ง `data-slot` ของตัวเองลงมาทับ — คืนค่าเดิม ไม่งั้น CSS/เทสต์ที่อิง slot ของปุ่มนี้หาไม่เจอ */ function keepSlot

(Component: ComponentType

, slot: string) { return function WithSlot(props: P) { return ; }; } /** * ไฟล์ ui เขียน `onClick={scrollNext} {...props}` — `onClick` ที่ TooltipTrigger ส่งลงมาจึงทับคำสั่งเลื่อน * ต้องเรียกเลื่อนเองต่อจาก handler ที่ได้รับ */ function PreviousButton({ onClick, ...props }: ComponentProps) { const { scrollPrev } = useCarousel(); return ( { onClick?.(event); scrollPrev(); }} /> ); } function NextButton({ onClick, ...props }: ComponentProps) { const { scrollNext } = useCarousel(); return ( { onClick?.(event); scrollNext(); }} /> ); } const AttachmentButton = keepSlot(UiAttachmentAction, "attachment-action"); const ScrollerButton = keepSlot(UiMessageScrollerButton, "message-scroller-button"); /** * ปุ่มไอคอนของไฟล์ shadcn (`components/ui/*` แก้มือไม่ได้) ที่ใช้ `Button` ดิบ จึงไม่มี tooltip * และชื่อปุ่มเป็นภาษาอังกฤษตายตัว — ตัวห่อชื่อเดิม props เดิม แอปได้ tooltip + ชื่อตาม `UiText` โดยไม่ต้องแก้โค้ด */ export function CarouselPrevious({ "aria-label": label, ...props }: ComponentProps) { const text = useUiText(); const name = label ?? text.carousel?.previous ?? "สไลด์ก่อนหน้า"; return ( ); } export function CarouselNext({ "aria-label": label, ...props }: ComponentProps) { const text = useUiText(); const name = label ?? text.carousel?.next ?? "สไลด์ถัดไป"; return ( ); } /** ปุ่มในแถวไฟล์แนบ — tooltip มาจาก `aria-label` ที่แอปส่ง (ปุ่มไอคอนต้องมีอยู่แล้ว) */ export function AttachmentAction(props: ComponentProps) { return ( ); } /** ปุ่มเลื่อนไปข้อความล่าสุด/แรกสุด — แอปส่ง `children` เองโดยไม่ตั้ง `aria-label` = เป็นปุ่มข้อความ ไม่มี tooltip */ export function MessageScrollerButton({ "aria-label": label, ...props }: ComponentProps) { const text = useUiText(); const fallback = props.direction === "start" ? (text.messageScroller?.toStart ?? "เลื่อนขึ้นบนสุด") : (text.messageScroller?.toEnd ?? "เลื่อนลงล่างสุด"); const name = label ?? (props.children ? undefined : fallback); return ( ); }