o
    m8i                      @  sf   d dl mZ d dlmZmZmZ zd dlmZ W n ey&   dddZY nw dd
dZ	dddZ
dS )    )annotations)ListDictAny)get_mail_themereturndictc                   C  s    ddddddddd	d
ddddS )NzDsystem-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serifz#020918z#071429z#122647z#0b3b73z#f5f7fbz#9ba4c4z#1fbf75z#f04444z#081937z#0d2142z#132750z#c3d1ff)
font_stackpage_bgcard_bgborder_colorbrand_color
text_colorsecondary_textsuccess_colorerror_colorstat_bgtable_header_bgtag_bgtag_text r   r   r   ,apps/wp_invoices_mail_app/email_templates.pyr   	   s   r   sstrc                 C  s    t | ddddddS )N&z&amp;<z&lt;>z&gt;)r   replace)r   r   r   r   _esc   s
   r   resultsList[Dict[str, Any]]c           *      C  sN  t  }|d }|d }|d }|d }|d }|d }|d }|d }	|d	 }
|d
 }|d }|d }|d }t| }tdd | D }|| }| sMd}n|dkrTd}nd| d}g }t| ddD ]\}}|dpq|dpqd}|dd}|d}|r|rd}|pd}n|dpi }|di }|d i }|d!i pi }|d"i pi }dTd'd(} | |d)}!| |d*}"| |d+pi d,}#| |d-}$|d.pd/}%g }&|!r|&d0t|! d1 |"r|&d2t|"  |#r|&d3t|#  |$r|&d4t|$ d5t|%  d6}|&rd7|&nd8}|d9| d:t| d:| d:| d;	 qbd<|}'| rGd=| d>| d?|' d@}(ndA}(dAg dB| dC| dD| dE| dF| dG| dH| dD| dI| dJ| dK|	 dL|
 dM| dN| dO| dP| dQ|( dR})|)S )Uu   
    Renderiza el correo HTML con branding para el resumen de facturas.
    (Versión en inglés; el texto plano sigue en español para compatibilidad).
    r	   r
   r   r   r   r   r   r   r   r   r   r   r   c                 s  s*    | ]}| d dr| dsdV  qdS )okTerror   N)get).0rr   r   r   	<genexpr>;   s   ( z,render_results_email_html.<locals>.<genexpr>z
        <p>We received your email but could not process any valid invoice.</p>
        <p>Please make sure the attachments are clear invoice images or PDF files.</p>
        r#   z@<p>We processed the attached invoice and here is the result:</p>z<p>We processed <strong>z/</strong> attached invoices. Summary below:</p>)startfilenameoriginal_filenamez(no filename)r!   Tr"   zNot processedzUnknown error.	extractedheadersupplierinvoicetotalsnoder   r   r   c                 S  s*   t | tr| dp| dpdS | pdS )Nverbatimcomputed )
isinstancer   r$   )r0   r   r   r   pick\   s   
z'render_results_email_html.<locals>.picknamenumberdate
issue_dategrand_totalcurrencyAUDzSupplier: <strong>z	</strong>zInvoice #: zDate: zTotal:  	Processedz<br>zExtracted successfully.z$
            <tr>
              <td>z</td>
              <td>z$</td>
            </tr>
            
z
      <div class="stats-row">
        <div class="stat-box">
          <div class="stat-label">Processed OK</div>
          <div class="stat-value stat-ok">z</div>
        </div>
        <div class="stat-box">
          <div class="stat-label">With errors</div>
          <div class="stat-value stat-err">aG  </div>
        </div>
      </div>

      <div class="details-title">Per-invoice details</div>
      <table class="details-table">
        <thead>
          <tr>
            <th>#</th>
            <th>File</th>
            <th>Status</th>
            <th>Details</th>
          </tr>
        </thead>
        <tbody>
          z'
        </tbody>
      </table>
      r3   u   <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Invoice Bot – Processing summary</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      background: z;
      font-family: z;
      color: z;
    }
    .wrapper {
      max-width: 640px;
      margin: 0 auto;
      padding: 24px 12px;
    }
    .card {
      background: z5;
      border-radius: 12px;
      border: 1px solid a+  ;
      padding: 22px 20px;
      box-sizing: border-box;
    }
    .brand-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      margin-bottom: 16px;
    }
    .brand-title {
      font-size: 18px;
      font-weight: 600;
      color: z;
    }
    .tag {
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      padding: 4px 8px;
      border-radius: 999px;
      background: a  ;
    }
    .intro {
      font-size: 14px;
      margin-bottom: 14px;
    }
    .stats-row {
      display: flex;
      gap: 12px;
      margin: 10px 0 18px 0;
      flex-wrap: wrap;
    }
    .stat-box {
      flex: 1 1 120px;
      border-radius: 10px;
      background: zv;
      padding: 10px 12px;
      box-sizing: border-box;
    }
    .stat-label {
      font-size: 11px;
      color: z;
      margin-bottom: 4px;
      text-transform: uppercase;
      letter-spacing: 0.04em;
    }
    .stat-value {
      font-size: 18px;
      font-weight: 600;
    }
    .stat-ok {
      color: z%;
    }
    .stat-err {
      color: aX  ;
    }
    .details-title {
      font-size: 13px;
      font-weight: 600;
      margin-bottom: 6px;
    }
    table.details-table {
      width: 100%;
      border-collapse: collapse;
      margin-bottom: 12px;
    }
    .details-table th,
    .details-table td {
      font-size: 12px;
      padding: 6px 8px;
      border-bottom: 1px solid ze;
      text-align: left;
      vertical-align: top;
    }
    .details-table th {
      background: zo;
      font-weight: 600;
    }
    .footer-note {
      margin-top: 12px;
      font-size: 11px;
      color: u  ;
    }
  </style>
</head>
<body>
  <div class="wrapper">
    <div class="card">
      <div class="brand-header">
        <div class="brand-title">Invoice Bot – Absolutems</div>
        <div class="tag">Summary</div>
      </div>

      <div class="intro">
        z
      </div>

      u  

      <div class="footer-note">
        If something looks wrong, please double-check the original supplier invoice.
        The system may have doubts in low-quality or partially readable areas.
        <br/><br/>
        Review PDFs are attached for every invoice processed successfully.
        Invoices marked as “Not processed” will not have a review PDF.
      </div>
    </div>
  </div>
</body>
</html>
N)r0   r   r   r   )r   lensum	enumerater$   appendr   join)*r   themer	   r
   r   r   r   r   r   r   r   r   r   r   r   totaln_okn_err
intro_html	rows_htmlidxr&   fnameok_flag	error_msgstatus_labeldetailsr+   r,   r-   invoice_blockr/   r5   supplier_nameinvoice_numberr9   r:   r;   parts
rows_blockstats_blockhtmlr   r   r   render_results_email_html%   s   





	
#+,;AKN^civy rX   N)r   r   )r   r   r   r   )r   r    r   r   )
__future__r   typingr   r   r   shared.branding.brandingr   	Exceptionr   rX   r   r   r   r   <module>   s   
	