# Document Templates — תבניות מסמכים משפטיים

## תבנית 1: כתב טענות (בקשה, תביעה, הגנה, ערעור)

```javascript
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
        AlignmentType, LevelFormat, BorderStyle, WidthType } = require('docx');

const PAGE_WIDTH = 11906;
const MARGINS = { top: 1134, right: 1134, bottom: 1134, left: 1134 };
const CONTENT_WIDTH = PAGE_WIDTH - MARGINS.left - MARGINS.right;

const noBorder = { style: BorderStyle.NONE, size: 0, color: "FFFFFF" };
const noBorders = { top: noBorder, bottom: noBorder, left: noBorder, right: noBorder };

// Header בית משפט — טבלה עם שם בית המשפט (ימין) ומספר תיק (שמאל)
function courtHeader(courtName, caseNumber) {
  return new Table({
    width: { size: CONTENT_WIDTH, type: WidthType.DXA },
    columnWidths: [CONTENT_WIDTH / 2, CONTENT_WIDTH / 2],
    visuallyRightToLeft: true,
    rows: [
      new TableRow({
        children: [
          new TableCell({
            width: { size: CONTENT_WIDTH / 2, type: WidthType.DXA },
            borders: noBorders,
            children: [new Paragraph({
              bidirectional: true, alignment: AlignmentType.START,
              children: [new TextRun({ text: courtName, bold: true, font: "David", size: 26, rightToLeft: true })]
            })]
          }),
          new TableCell({
            width: { size: CONTENT_WIDTH / 2, type: WidthType.DXA },
            borders: noBorders,
            children: [new Paragraph({
              bidirectional: true, alignment: AlignmentType.END,
              children: [new TextRun({ text: caseNumber, bold: true, font: "David", size: 26, rightToLeft: true })]
            })]
          })
        ]
      })
    ]
  });
}

function mainTitle(text) {
  return new Paragraph({
    bidirectional: true, alignment: AlignmentType.CENTER,
    spacing: { before: 300, after: 300 },
    children: [new TextRun({ text, bold: true, font: "David", size: 28, rightToLeft: true, underline: {} })]
  });
}

function subHeading(text) {
  return new Paragraph({
    bidirectional: true, alignment: AlignmentType.START,
    spacing: { before: 240, after: 120 },
    children: [new TextRun({ text, bold: true, font: "David", size: 24, rightToLeft: true, underline: {} })]
  });
}

const doc = new Document({
  numbering: {
    config: [{
      reference: "legal-clauses",
      levels: [{
        level: 0, format: LevelFormat.DECIMAL, text: "%1.",
        alignment: AlignmentType.START, suffix: "tab",
        style: { paragraph: { indent: { left: 360, hanging: 360 } } }
      }]
    }]
  },
  sections: [{
    properties: {
      page: { size: { width: PAGE_WIDTH, height: 16838 }, margin: MARGINS },
      bidi: true
    },
    children: [
      courtHeader("בית המשפט המחוזי בתל אביב", "ת\"א 12345-01-26"),
      mainTitle("כתב תביעה"),
      // ... פרטי צדדים, סעיפים, חתימה
    ]
  }]
});
```

---

## תבנית 2: מכתב התראה

```javascript
function letterHeader(firmName, address, phone, email) {
  return [
    new Paragraph({
      bidirectional: true, alignment: AlignmentType.START,
      children: [new TextRun({ text: firmName, bold: true, font: "David", size: 28, rightToLeft: true })]
    }),
    new Paragraph({
      bidirectional: true, alignment: AlignmentType.START,
      children: [new TextRun({ text: address, font: "David", size: 22, rightToLeft: true })]
    }),
    new Paragraph({
      bidirectional: true, alignment: AlignmentType.START,
      spacing: { after: 300 },
      children: [new TextRun({ text: `טל': ${phone} | ${email}`, font: "David", size: 22, rightToLeft: true })]
    }),
  ];
}

function subjectLine(text) {
  return new Paragraph({
    bidirectional: true, alignment: AlignmentType.CENTER,
    spacing: { before: 200, after: 200 },
    children: [
      new TextRun({ text: "הנדון: ", bold: true, font: "David", size: 24, rightToLeft: true }),
      new TextRun({ text, bold: true, font: "David", size: 24, rightToLeft: true, underline: {} })
    ]
  });
}

// שימוש:
sections: [{
  properties: { page: { size: { width: 11906, height: 16838 }, margin: { top: 1417, right: 1417, bottom: 1417, left: 1417 } }, bidi: true },
  children: [
    ...letterHeader("משרד עו\"ד כהן ושות'", "רח' הרצל 1, תל אביב", "03-1234567", "office@cohen-law.co.il"),
    new Paragraph({
      bidirectional: true, alignment: AlignmentType.START,
      children: [new TextRun({ text: "תאריך: 10.2.2026", font: "David", size: 24, rightToLeft: true })]
    }),
    new Paragraph({
      bidirectional: true, alignment: AlignmentType.START,
      spacing: { before: 200 },
      children: [new TextRun({ text: "לכבוד: [שם הנמען]", font: "David", size: 24, rightToLeft: true })]
    }),
    subjectLine("התראה בטרם נקיטת הליכים משפטיים"),
  ]
}]
```

---

## תבנית 3: הסכם/חוזה

```javascript
const CONTENT_WIDTH = 9638; // A4 עם שוליים 2.5 ס"מ
const noBorders = { /* ראה תבנית 1 */ };

function contractTitle(text) {
  return new Paragraph({
    bidirectional: true, alignment: AlignmentType.CENTER,
    spacing: { after: 300 },
    children: [new TextRun({ text, bold: true, font: "David", size: 32, rightToLeft: true })]
  });
}

function partyClause(label, name, id, address, alias) {
  return new Paragraph({
    bidirectional: true, alignment: AlignmentType.BOTH,
    spacing: { after: 120 },
    children: [
      new TextRun({ text: `${label}: `, bold: true, font: "David", size: 24, rightToLeft: true }),
      new TextRun({ text: `${name}, ח.פ./ת.ז. ${id}, מ${address} (להלן: "`, font: "David", size: 24, rightToLeft: true }),
      new TextRun({ text: alias, bold: true, font: "David", size: 24, rightToLeft: true }),
      new TextRun({ text: '")', font: "David", size: 24, rightToLeft: true }),
    ]
  });
}

function signatureTable(contentWidth) {
  return new Table({
    width: { size: contentWidth, type: WidthType.DXA },
    columnWidths: [contentWidth / 2, contentWidth / 2],
    visuallyRightToLeft: true,
    rows: [new TableRow({
      children: [
        new TableCell({
          borders: noBorders,
          children: [
            new Paragraph({ bidirectional: true, alignment: AlignmentType.CENTER,
              children: [new TextRun({ text: "_________________", font: "David", size: 24, rightToLeft: true })] }),
            new Paragraph({ bidirectional: true, alignment: AlignmentType.CENTER,
              children: [new TextRun({ text: "צד א'", font: "David", size: 24, rightToLeft: true })] })
          ]
        }),
        new TableCell({
          borders: noBorders,
          children: [
            new Paragraph({ bidirectional: true, alignment: AlignmentType.CENTER,
              children: [new TextRun({ text: "_________________", font: "David", size: 24, rightToLeft: true })] }),
            new Paragraph({ bidirectional: true, alignment: AlignmentType.CENTER,
              children: [new TextRun({ text: "צד ב'", font: "David", size: 24, rightToLeft: true })] })
          ]
        })
      ]
    })]
  });
}

sections: [{
  properties: { page: { size: { width: 11906, height: 16838 }, margin: { top: 1417, right: 1417, bottom: 1417, left: 1417 } }, bidi: true },
  children: [
    contractTitle("הסכם שירותים"),
    new Paragraph({
      bidirectional: true, alignment: AlignmentType.CENTER,
      children: [new TextRun({ text: "נערך ונחתם בתל אביב ביום __________", font: "David", size: 24, rightToLeft: true })]
    }),
    partyClause("מצד אחד", "[שם]", "[מספר]", "[כתובת]", "המזמין"),
    partyClause("מצד שני", "[שם]", "[מספר]", "[כתובת]", "הספק"),
    // הואילים + סעיפים...
    new Paragraph({
      bidirectional: true, alignment: AlignmentType.CENTER,
      spacing: { before: 400, after: 300 },
      children: [new TextRun({ text: "ולראיה באו הצדדים על החתום:", bold: true, font: "David", size: 24, rightToLeft: true })]
    }),
    signatureTable(CONTENT_WIDTH)
  ]
}]
```
