<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>چاپ قرارداد {{ instance.code }}</title>
  {% load static %}

  <!-- Match app fonts and theme -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500,1,600,1,700&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="{% static 'assets/vendor/fonts/boxicons.css' %}">
  <link rel="stylesheet" href="{% static 'assets/vendor/fonts/fontawesome.css' %}">
  <link rel="stylesheet" href="{% static 'assets/vendor/css/rtl/core.css' %}">
  <link rel="stylesheet" href="{% static 'assets/vendor/css/rtl/theme-default.css' %}">
  <link rel="stylesheet" href="{% static 'assets/css/demo.css' %}">
  <link rel="stylesheet" href="{% static 'assets/css/persian-fonts.css' %}">

  <style>
    @page { size: A4; margin: 1.2cm; }
    .invoice-header { border-bottom: 1px solid #dee2e6; padding-bottom: 16px; margin-bottom: 24px; }
    .brand-box { width:64px; height:64px; display:flex; align-items:center; justify-content:center; background:#eef2ff; border-radius:8px; }
    .logo { max-height: 58px; max-width: 120px; }
    .contract-title { font-size: 20px; font-weight: 600; }
    .small-muted { font-size: 12px; color: #6c757d; }
    .signature-box { border: 1px dashed #ccc; height: 210px; display:flex; align-items:center; justify-content:center; }
  </style>
  <script>
    window.onload = function(){
      window.print();
      setTimeout(function(){ window.close(); }, 200);
    };
  </script>
</head>
<body>
  <div class="container-fluid">
    <!-- Header: Company and contract info -->
    <div class="invoice-header">
      <div class="small text-end text-muted mb-2">تاریخ: {{ contract.jcreated_date }} | کد درخواست: {{ instance.code }}</div>
      <h5 class="text-center mb-3">
        {% if instance.broker and instance.broker.company %}
          {{ instance.broker.company.name }}
        {% elif template.company %}
          {{ template.company.name }}
        {% else %}
          شرکت آب منطقه‌ای
        {% endif %}
      </h5>
      <h4 class="text-center mb-3">{{ contract.template.name }}</h4>
    </div>

    <!-- Contract body -->
    <div style="white-space: pre-line; line-height: 1.9;">{{ contract.rendered_body|safe }}</div>
    <hr>

    <!-- Signatures -->
    <div class="row mt-4">
      <div class="col-6 text-center">
        <div>امضای مشترک</div>
        <div class="signature-box mt-2"></div>
      </div>
      <div class="col-6 text-center">
        <div>امضای شرکت</div>
        <div class="signature-box mt-2">
          {% if instance.broker and instance.broker.company and instance.broker.company.signature %}
            <img src="{{ instance.broker.company.signature.url }}" alt="امضای شرکت" style="max-height: 200px;" />
          {% elif contract.template.company and contract.template.company.signature %}
            <img src="{{ contract.template.company.signature.url }}" alt="امضای شرکت" style="max-height: 200px;" />
          {% endif %}
        </div>
      </div>
    </div>
  </div>
</body>
</html>


