import type { ReactNode } from 'react';
import { turn } from '@/site/components/art/kit';
import { cx } from '@/site/lib/cx';
import type { FactKey } from '@/site/types';

/**
 * Line icons of a treatment's quick facts, on a 24×24 grid. Their strokes
 * draw themselves when the fact comes into view (class sk, see site.css);
 * the label next to each one says what it is, so they are decorative.
 */
const icons: Record<FactKey, ReactNode> = {
    // A clock
    duration: (
        <>
            <circle pathLength={1} className="sk" cx="12" cy="12" r="8.5" />
            <path
                pathLength={1}
                className="sk"
                style={turn(4)}
                d="M12 7.5V12l3 2"
            />
        </>
    ),
    // A drop
    anesthesia: (
        <>
            <path
                pathLength={1}
                className="sk"
                d="M12 3.5c3.6 4.3 5.5 7.1 5.5 10a5.5 5.5 0 0 1-11 0c0-2.9 1.9-5.7 5.5-10Z"
            />
            <path
                pathLength={1}
                className="sk"
                style={turn(4)}
                d="M9.6 14a2.5 2.5 0 0 0 2.4 2.4"
            />
        </>
    ),
    // A calendar with a day ticked
    downtime: (
        <>
            <rect
                pathLength={1}
                className="sk"
                x="4"
                y="5.5"
                width="16"
                height="14.5"
                rx="2.5"
            />
            <path
                pathLength={1}
                className="sk"
                style={turn(3)}
                d="M8 3.5v4M16 3.5v4M4 10h16"
            />
            <path
                pathLength={1}
                className="sk"
                style={turn(6)}
                d="m9 14.6 2 2 4-4"
            />
        </>
    ),
    // A rising sun
    onset: (
        <>
            <path
                pathLength={1}
                className="sk"
                d="M3.5 18h17M7 18a5 5 0 0 1 10 0"
            />
            <path
                pathLength={1}
                className="sk"
                style={turn(4)}
                d="M12 6.5v3M5.6 9.8l2 2M18.4 9.8l-2 2"
            />
        </>
    ),
    // An hourglass
    longevity: (
        <>
            <path pathLength={1} className="sk" d="M7 4h10M7 20h10" />
            <path
                pathLength={1}
                className="sk"
                style={turn(3)}
                d="M8 4c0 4 4 5 4 8s-4 4-4 8M16 4c0 4-4 5-4 8s4 4 4 8"
            />
        </>
    ),
    // Two arrows going round
    sessions: (
        <>
            <path
                pathLength={1}
                className="sk"
                d="M5 11a7 7 0 0 1 12-4.5L19 8M19 4v4h-4"
            />
            <path
                pathLength={1}
                className="sk"
                style={turn(4)}
                d="M19 13a7 7 0 0 1-12 4.5L5 16M5 20v-4h4"
            />
        </>
    ),
};

export function FactIcon({
    name,
    className,
}: {
    name: FactKey;
    className?: string;
}) {
    return (
        <svg
            viewBox="0 0 24 24"
            aria-hidden="true"
            stroke="currentColor"
            strokeWidth="1.4"
            className={cx('art', className)}
        >
            {icons[name]}
        </svg>
    );
}
