"""Video and app icons (iShatat, 12 November 2026: "all seven, and with creativity").

The lower third is the line and its point with a name over it: on screen the line draws from the left, the point
lands at its end, then the words rise. Captions are plain Ink words with a soft shadow, in English and in Arabic.
The icon grid shows how the S. sits on an app icon: its letter centred on the tile, 40 % of its height, the point
hanging outside the centre as a full stop hangs outside a line.

Usage: python3 -I make_video_and_icons.py            (all of them)
       python3 -I make_video_and_icons.py lower-third"""
import pathlib, sys
HERE = pathlib.Path(__file__).resolve().parent
sys.path.insert(0, str(HERE))
import make_templates as T
from make_templates import INK, GRAPHITE, NIGHT, S_PATH, template, line_and_point

BRAND = HERE.parents[1]
ARABIC_FONT = (BRAND / "fonts/Alexandria/Alexandria[wght].ttf").as_uri()
MINE = []

def mine(key, *args, **kw):
    MINE.append(key)
    return template(key, *args, **kw)

def film_frame():
    """A stand-in for the picture under the words: dark, with one soft light, as our films are lit."""
    return ('<div style="position:absolute;inset:0;background:radial-gradient(70% 90% at 70% 35%, #2B2D33 0%, #17181C 55%, #0B0C0E 100%)"></div>'
            '<div class="label" style="position:absolute;right:80px;top:80px;font-size:18px;color:#4A4B50">The film</div>')

@mine("lower-third", "Video lower third", 1920, 1080, "A name on screen: the line draws, the point lands, the words rise; 4 s on screen")
def lower_third():
    m = 80
    return f'''{film_frame()}
<div style="position:absolute;left:{m}px;bottom:{m + 120}px;font-size:46px;font-stretch:112%;color:{INK}">iShatat</div>
<div style="position:absolute;left:{m}px;bottom:{m + 76}px;font-size:26px;color:{GRAPHITE}">Founder, SHATATiON</div>
<div style="position:absolute;left:{m}px;bottom:{m + 40}px">{line_and_point(420, "rgba(241,240,236,.5)", INK)}</div>'''

def caption(text, arabic=False):
    face = f"font-family:'Alexandria';direction:rtl;" if arabic else ""
    return (f'<div style="position:absolute;left:240px;right:240px;bottom:80px;text-align:center;{face}font-size:44px;line-height:1.35;'
            f'color:{INK};text-shadow:0 2px 14px rgba(0,0,0,.65), 0 0 2px rgba(0,0,0,.5)">{text}</div>')

ARABIC_FACE = f'@font-face {{ font-family: "Alexandria"; src: url("{ARABIC_FONT}"); font-weight: 100 900; }}'

@mine("captions", "Video captions", 1920, 1080, "Captions: two lines at most, about 42 letters each, Ink with a soft shadow, never a box")
def captions():
    return film_frame() + caption("Every product starts as a question.<br>We keep asking until there is no better answer.")

@mine("captions-arabic", "Video captions, Arabic", 1920, 1080, "Arabic captions in Alexandria, right to left, the same size and place")
def captions_arabic():
    return f'<style>{ARABIC_FACE}</style>' + film_frame() + caption("كل منتج يبدأ بسؤال.<br>ونظل نسأل حتى لا يبقى جواب أفضل.", arabic=True)

@mine("app-icon-grid", "App icon grid", 1024, 1024, "How the S. sits on an app icon: the letter centred, 40 % of the tile, the point hanging outside")
def app_icon_grid():
    k = .40 * 1024 / 100                       # the letter (0 to 100 units, stroke included) is 40 % of the tile
    tx, ty = 512 - 47 * k, 512 - 50 * k        # the letter's own centre, (47, 50), on the tile's centre
    line = 'stroke="#3A3C42" stroke-width="2" fill="none"'
    key = 'stroke="#22D3EE" stroke-width="2" fill="none" stroke-dasharray="10 8"'
    return f'''<svg width="1024" height="1024" viewBox="0 0 1024 1024" style="position:absolute;inset:0">
<rect width="1024" height="1024" fill="{NIGHT}"/>
<rect x="0" y="0" width="1024" height="1024" rx="229" {line}/>
<circle cx="512" cy="512" r="410" {line}/>
<path d="M512 0 V1024 M0 512 H1024" {line}/>
<rect x="{tx:.1f}" y="{ty:.1f}" width="{94 * k:.1f}" height="{100 * k:.1f}" {key}/>
<g transform="translate({tx:.2f} {ty:.2f}) scale({k:.4f})"><path d="{S_PATH}" fill="none" stroke="{INK}" stroke-width="13" stroke-miterlimit="12"/><circle cx="115" cy="91" r="9" fill="{INK}"/></g>
<g font-family="Mona Sans, sans-serif" font-size="22" fill="#9A9BA0">
<text x="{tx:.0f}" y="{ty - 18:.0f}">The letter, centred: 40 %</text>
<text x="{tx + 118 * k:.0f}" y="{ty + 100 * k + 64:.0f}" text-anchor="middle">The point hangs outside</text>
<text x="40" y="1000">The tile is square; the system rounds its corners</text>
</g></svg>'''

if __name__ == "__main__":
    T.build(tuple(sys.argv[1:]) or tuple(MINE))
