import { Fragment } from 'react';
import { ViewScene } from '@/site/components/motion/scene';
import { cx } from '@/site/lib/cx';
import type { DepartmentPanel } from '@/site/types';

/**
 * Two lines of oversized type that slide in opposite directions as the page
 * scrolls — the names of the main departments, closing their panels:
 * hair, dental, medical aesthetics, men's health. Decoration only: the
 * same names are real headings and links in the section before, so this
 * band is hidden from assistive technology.
 */
export function KineticBand({
    departments,
}: {
    departments: Pick<DepartmentPanel, 'key' | 'label' | 'lang' | 'accent'>[];
}) {
    const half = Math.ceil(departments.length / 2);
    // Each line starts with a different half, so the two never read the same.
    const rows = [
        departments,
        [...departments.slice(half), ...departments.slice(0, half)],
    ];

    return (
        <ViewScene
            aria-hidden
            smooth={120}
            className="kinetic stage-dark overflow-clip py-10 md:py-14"
        >
            {rows.map((row, line) => (
                <div
                    key={line}
                    className={cx(
                        'kinetic-row font-display',
                        line === 1 && 'kinetic-row-back',
                    )}
                >
                    {row.map((department, index) => (
                        <Fragment key={department.key}>
                            <span
                                lang={department.lang ?? undefined}
                                data-accent={department.accent}
                                className={
                                    (index + line) % 2 === 0
                                        ? 'kinetic-outline'
                                        : 'font-[560] text-accent'
                                }
                            >
                                {department.label}
                            </span>
                            <span className="size-[0.14em] shrink-0 rotate-45 self-center bg-accent opacity-70" />
                        </Fragment>
                    ))}
                </div>
            ))}
        </ViewScene>
    );
}
