import { ArrowRight } from '@/site/components/ui/icons';
import type { Rail } from '@/site/hooks/use-rail';
import { useT } from '@/site/i18n';
import { cx } from '@/site/lib/cx';

const button =
    'grid size-11 place-items-center rounded-full border border-line-strong text-fg transition-[background-color,color,border-color,opacity] duration-300 ease-out-expo hover:border-fg hover:bg-fg hover:text-stage disabled:pointer-events-none disabled:opacity-30';

type RailControlsProps = {
    /** State of the row the buttons belong to (see `useRail`). */
    rail: Rail;
    className?: string;
};

/**
 * Previous / next buttons of a horizontal row of cards. They exist only
 * while the row really has more than fits (so not on the server, and not
 * where a pinned scene moves the row), and from tablet width up: on phones
 * the row is swiped.
 */
export function RailControls({ rail, className }: RailControlsProps) {
    const t = useT();

    if (!rail.overflowing) {
        return null;
    }

    return (
        <div className={cx('hidden shrink-0 gap-3 sm:flex', className)}>
            <button
                type="button"
                aria-label={t.common.showPrevious}
                disabled={rail.atStart}
                onClick={() => rail.move(-1)}
                className={button}
            >
                <ArrowRight className="size-5 rotate-180 rtl:rotate-0" />
            </button>
            <button
                type="button"
                aria-label={t.common.showNext}
                disabled={rail.atEnd}
                onClick={() => rail.move(1)}
                className={button}
            >
                <ArrowRight className="size-5 rtl:rotate-180" />
            </button>
        </div>
    );
}
