#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""给海报加：公司 slogan（顶栏居中）+ 页脚联系方式行（电话/网址/邮箱/地址），并收紧图表高度腾空间。"""
import io, sys

P = '/Users/liuxinyuan/Desktop/Hermes输出-工作类/科研2026秋季促销/华南农大海报_20260920/gen_poster.py'
s = io.open(P, encoding='utf-8').read()

E = []
# ① 常量
E.append((
    "COMPANY = '珠海宝锐生物科技有限公司'",
    "COMPANY = '珠海宝锐生物科技有限公司'\n"
    "SLOGAN = '守护生命健康，缔造美好生活'\n"
    "TEL = '0756-8699969'\n"
    "WEB = 'www.biori.com'\n"
    "MAIL = 'marketing@biori.com'\n"
    "ADDR = '珠海市香洲区水岸一路88号'"))
# ② 顶栏 slogan
E.append((
    "  .topbar { flex-shrink:0; height:20mm; background:#fff; border-bottom:2.5px solid #0a3d62;",
    "  .topbar { position:relative; flex-shrink:0; height:19.5mm; background:#fff; border-bottom:2.5px solid #0a3d62;"))
E.append((
    "  .topbar .tb-r .lo { color:#7a8b9c; font-weight:500; letter-spacing:.5px; }",
    "  .topbar .tb-r .lo { color:#7a8b9c; font-weight:500; letter-spacing:.5px; }\n"
    "  .tb-slogan { position:absolute; left:50%; top:50%; transform:translate(-50%,-50%);\n"
    "               font-size:10pt; font-weight:900; letter-spacing:2.5px; color:#0a3d62; white-space:nowrap; }\n"
    "  .tb-slogan i { font-style:normal; color:#00a3a3; }"))
E.append((
    '<div class="tb-r">技术报告会 <span class="lo">/ TECHNICAL SEMINAR</span></div>',
    '<div class="tb-slogan">守护生命健康<i>，</i>缔造美好生活</div>\n'
    '    <div class="tb-r">技术报告会 <span class="lo">/ TECHNICAL SEMINAR</span></div>'))
# ③ 页脚两排
E.append((
    "  .foot { flex-shrink:0; margin-top:auto; background:linear-gradient(135deg,#0a3d62,#0060c0); color:#fff;\n"
    "          padding:3mm 11mm 4mm; display:flex; align-items:center; justify-content:space-between; gap:5mm; }",
    "  .foot { flex-shrink:0; margin-top:auto; background:linear-gradient(135deg,#0a3d62,#0060c0); color:#fff;\n"
    "          padding:2.6mm 11mm 3mm; display:flex; flex-direction:column; }\n"
    "  .foot .frow { display:flex; align-items:center; justify-content:space-between; gap:5mm; }\n"
    "  .foot .fcontact { margin-top:1.9mm; padding-top:1.7mm; border-top:1px solid rgba(255,255,255,.22);\n"
    "                    font-size:7.3pt; text-align:center; letter-spacing:.2px; opacity:.94; line-height:1.4; }\n"
    "  .foot .fcontact b { font-weight:600; opacity:.82; margin-right:.6mm; }\n"
    "  .foot .fcontact a { color:#bfe6ff; text-decoration:none; }\n"
    "  .foot .fcontact span.sep { opacity:.4; margin:0 2.4mm; }"))
E.append((
    '  <div class="foot">\n    <div class="l">__COMPANY__</div>',
    '  <div class="foot">\n   <div class="frow">\n    <div class="l">__COMPANY__</div>'))
E.append((
    '    <div class="r">2026年9月22日（周二）<br>14:00–16:30<br>__PLACE__</div>\n  </div>',
    '    <div class="r">2026年9月22日（周二）<br>14:00–16:30<br>__PLACE__</div>\n   </div>\n'
    '   <div class="fcontact"><b>电话</b>__TEL__<span class="sep">|</span><b>网址</b>'
    '<a href="https://__WEB__">__WEB__</a><span class="sep">|</span><b>邮箱</b>'
    '<a href="mailto:__MAIL__">__MAIL__</a><span class="sep">|</span><b>地址</b>__ADDR__</div>\n  </div>'))
# ④ 收紧图表
E.append(("  .fig.f-main img { height:47mm; }", "  .fig.f-main img { height:43.5mm; }"))
E.append(("  .fig.f-tall img { height:47mm; }", "  .fig.f-tall img { height:43.5mm; }"))
E.append(("  .fig.f-w img { height:29mm; }", "  .fig.f-w img { height:27mm; }"))
E.append(("  .fig.f-wide img { height:29mm; }", "  .fig.f-wide img { height:27mm; }"))
E.append(("  .fig.f-sm img { height:47mm; }", "  .fig.f-sm img { height:43.5mm; }"))
# ⑤ 替换表 + 断言
E.append((
    "   .replace('__COMPANY__', COMPANY) \\",
    "   .replace('__COMPANY__', COMPANY) \\\n"
    "   .replace('__SLOGAN__', SLOGAN) \\\n"
    "   .replace('__TEL__', TEL) \\\n"
    "   .replace('__WEB__', WEB) \\\n"
    "   .replace('__MAIL__', MAIL) \\\n"
    "   .replace('__ADDR__', ADDR) \\"))
E.append((
    "'__DATE__', '__PLACE__', '__COMPANY__', '__P1__', '__P2__', '__P3__',",
    "'__DATE__', '__PLACE__', '__COMPANY__',\n"
    "                             '__P1__', '__P2__', '__P3__',"))

n = 0
for a, b in E:
    if a in s:
        s = s.replace(a, b, 1); n += 1
    else:
        print('  ⚠️ 未命中:', a[:70].replace('\n', '⏎'))
io.open(P, 'w', encoding='utf-8').write(s)
print('  ✅ %d/%d 处已应用' % (n, len(E)))
