# -*- coding: utf-8 -*-
import sys
f = sys.argv[1]
s = open(f, encoding="utf-8").read()
T = "\t"

def rep(old, new, s):
    if s.count(old) != 1:
        print("CLIENT ANCHOR PROBLEM:", "count=", s.count(old)); sys.exit(1)
    return s.replace(old, new, 1)

old_c = (
    T*4 + "// FERMI: bandeau charcoal + label blanc (Adresse a)\n"
    + T*4 + "$pdf->RoundedRect($posx, $posy - 5, $widthrecbox, 5, $this->corner_radius, '1111', 'F', array(), array(55, 55, 55));\n"
    + T*4 + "$pdf->SetTextColor(255, 255, 255);\n"
    + T*4 + "$pdf->SetFont('', 'B', $default_font_size - 2);\n"
    + T*4 + "$pdf->SetXY($posx + 1.5, $posy - 4.6);\n"
    + T*4 + '$pdf->MultiCell($widthrecbox - 3, 4, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);\n'
    + T*4 + "$pdf->SetTextColor(0, 0, 0);\n"
    + T*4 + "$pdf->SetFont('', '', $default_font_size - 2);\n"
    + T*4 + "$pdf->SetDrawColor(180, 180, 180);\n"
    + T*4 + "$pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1111', 'D');"
)
new_c = (
    T*4 + "// FERMI: bloc client epure (label simple + cadre leger)\n"
    + T*4 + "$pdf->SetTextColor(0, 0, 0);\n"
    + T*4 + "$pdf->SetFont('', '', $default_font_size - 2);\n"
    + T*4 + "$pdf->SetXY($posx + 2, $posy - 5);\n"
    + T*4 + '$pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);\n'
    + T*4 + "$pdf->SetDrawColor(180, 180, 180);\n"
    + T*4 + "$pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius, '1111', 'D');"
)
s = rep(old_c, new_c, s)
open(f, "w", encoding="utf-8").write(s)
print("client epure:", f.split('/')[-1])
