import type { ReactNode } from 'react';
import { about, depth, turn } from '@/site/components/art/kit';

/**
 * The mark set on the sheet, by page key (SitePresenter::LEGAL_PAGES), on
 * a 24×24 grid: a shield for the data-protection notice, a padlock for the
 * privacy policy, a bitten biscuit for the cookie policy. They are drawn
 * 6.5 times larger, so their strokes are set thin by hand (a non-scaling
 * stroke would break the dashes that draw them).
 */
const THIN = 0.26;

const marks: Record<string, ReactNode> = {
    kvkk: (
        <>
            <path
                pathLength={1}
                className="pane ac sk"
                style={{ strokeWidth: THIN }}
                d="M12 3 4.5 6v5.5c0 4.6 3.1 8 7.5 9.5 4.4-1.5 7.5-4.9 7.5-9.5V6L12 3Z"
            />
            <path
                pathLength={1}
                className="ac sk"
                style={turn(16, { strokeWidth: THIN })}
                d="m9 12 2.2 2.2L15.2 10"
            />
        </>
    ),
    privacy: (
        <>
            <rect
                pathLength={1}
                x="5"
                y="11"
                width="14"
                height="10"
                rx="2.5"
                className="pane ac sk"
                style={{ strokeWidth: THIN }}
            />
            <path
                pathLength={1}
                className="ac sk"
                style={turn(15, { strokeWidth: THIN })}
                d="M7.5 11V8a4.5 4.5 0 0 1 9 0v3"
            />
            <path
                pathLength={1}
                className="ac sk"
                style={turn(17, { strokeWidth: THIN })}
                d="M12 15v2.6"
            />
        </>
    ),
    cookies: (
        <>
            <path
                pathLength={1}
                className="pane ac sk"
                style={{ strokeWidth: THIN }}
                d="M12 3a9 9 0 1 0 9 9 4.5 4.5 0 0 1-5-4 4.5 4.5 0 0 1-4-5Z"
            />
            {[
                [9, 10],
                [8.4, 15],
                [13.4, 16.6],
                [13.8, 12],
            ].map(([x, y], index) => (
                <circle
                    key={index}
                    cx={x}
                    cy={y}
                    r="0.9"
                    className="af sf"
                    style={turn(16 + index)}
                />
            ))}
        </>
    ),
};

/**
 * Drawing of a legal page: a sheet of text being written, with the mark of
 * the page set on its corner.
 */
export function LegalArt({ page }: { page: string }) {
    return (
        <svg viewBox="0 0 400 400" aria-hidden="true" className="art size-full">
            <g className="so" data-depth="" style={depth(-1)}>
                <circle
                    cx="200"
                    cy="200"
                    r="176"
                    className="ln art-turn"
                    opacity="0.4"
                    strokeDasharray="1 11"
                    style={about(200, 200)}
                />
            </g>

            {/* The sheet and its text */}
            <g data-depth="" style={depth(1)}>
                <rect
                    pathLength={1}
                    x="84"
                    y="52"
                    width="196"
                    height="272"
                    rx="16"
                    className="pane ln sk"
                />
                <path
                    pathLength={1}
                    className="ln sk"
                    strokeWidth="4"
                    style={turn(3)}
                    d="M108 88h96"
                />
                {[118, 136, 154, 184, 202, 220, 238].map((y, index) => (
                    <path
                        key={y}
                        pathLength={1}
                        className="ln sk"
                        opacity="0.7"
                        style={turn(5 + index)}
                        d={`M108 ${y}h${index === 2 || index === 6 ? 92 : 148}`}
                    />
                ))}
            </g>

            {/* The mark */}
            <g data-depth="" style={depth(2.5)}>
                <g className="so" style={turn(12)}>
                    <circle
                        cx="278"
                        cy="286"
                        r="92"
                        className="ac art-turn"
                        opacity="0.55"
                        strokeDasharray="2 8"
                        style={about(278, 286, { '--turn': '80s' })}
                    />
                </g>
                <g transform="translate(200 208) scale(6.5)" style={turn(13)}>
                    {marks[page] ?? marks.kvkk}
                </g>
            </g>
        </svg>
    );
}
