# -*- coding: utf-8 -*-
"""Kiem chung DOCX ban de nghi bo sung + copy ban de gui (duong dan khong dau cach)."""
import os, re, shutil
from docx import Document

D = r'C:\Claw 2\Nghien cuu\Du-an-A-Quy-trinh-son'
P = os.path.join(D, 'DE-NGHI-BO-SUNG_05-10-2026.docx')
doc = Document(P)
txt = '\n'.join(p.text for p in doc.paragraphs)
for t in doc.tables:
    for row in t.rows:
        for c in row.cells:
            txt += '\n' + c.text

print('=== %s : %d byte ===' % (os.path.basename(P), os.path.getsize(P)))
print('   doan van:', len(doc.paragraphs), '| bang:', len(doc.tables), '| anh:', len(doc.inline_shapes))
print('   emoji :', len(re.findall(r'[\U0001F000-\U0001FAFF\U00002600-\U000027BF]', txt)))
print('   ten rieng con lai:', sum(txt.count(k) for k in ['Trendworld', 'Nguyễn Văn Tươi', 'N.D. Vững', 'Bình Thạnh chem']))
print('   tieng Viet co dau:', all(w in txt for w in ['Ngăn dầu', 'ĐỀ NGHỊ BỔ SUNG', 'tẩy trắng', 'bột bụi']))
print('   so dong tung bang:', [len(t.rows) for t in doc.tables])
print()
print('--- 8 heading dau ---')
n = 0
for p in doc.paragraphs:
    if p.style.name.startswith('Heading') and p.text.strip():
        print('   [%s] %s' % (p.style.name, p.text[:95]))
        n += 1
        if n >= 8:
            break

out = os.path.join(os.environ['LOCALAPPDATA'], 'hermes', 'cache', 'gui_duan_a')
os.makedirs(out, exist_ok=True)
shutil.copy2(P, out)
print()
print('   da copy ban gui:', os.path.join(out, os.path.basename(P)), os.path.getsize(os.path.join(out, os.path.basename(P))), 'byte')
