"""passport_m03 wrapper - adapts write_passport_fixed for app.py interface."""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "scripts"))

from write_passport_fixed import (
    write_passport_fixed, FONT_DIR, load_font, draw_text_with_texture,
    M02_FIELDS, hex_to_rgb,
)


M02_FIELD_POS = {
    "type":          (603, 1060),
    "country_code":  (743, 1060),
    "nationality":   (603, 1196),
    "authority":     (909, 1391),
}

M02_FIELD_SIZE = {
    "type": 18,
    "country_code": 18,
    "nationality": 24,
    "authority": 20,
}

COLORS = {"val": "#111111", "label": "#666666", "title": "#1a1a1a", "mrz": "#111111"}


def draw_text_mask(img, xy, text, font, fill, anchor):
    from PIL import ImageDraw
    draw = ImageDraw.Draw(img)
    draw_text_with_texture(draw, img, xy, text, font, fill, anchor)


def write_passport(img_path, out_path, data, template="m02", skip_header=False, skip_fixed=False, debug=False, no_affine=False):
    write_passport_fixed(img_path, out_path, data, debug=debug, skip_header=skip_header, no_affine=no_affine)
