
    hi0                        d Z ddlmZ ddlZddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZmZmZ ddlmZmZmZmZ erdd	lmZ dd
lmZ  G d de          Z G d de          ZdS )z4Custom element classes related to document comments.    )annotationsN)TYPE_CHECKINGCallablecast)nsdecls)	parse_xml)ST_DateTimeST_DecimalNumber	ST_String)BaseOxmlElementOptionalAttributeRequiredAttribute
ZeroOrMore)CT_Tbl)CT_Pc                  L    e Zd ZU dZded<    ed          ZddZddZddZ	dS )CT_Commentsa  `w:comments` element, the root element for the comments part.

    Simply contains a collection of `w:comment` elements, each representing a single comment. Each
    contained comment is identified by a unique `w:id` attribute, used to reference the comment
    from the document text. The offset of the comment in this collection is arbitrary; it is
    essentially a _set_ implemented as a list.
    zlist[CT_Comment]comment_lstz	w:commentreturn
CT_Commentc           
         |                                  }t          t          t          dt	          d           d| d                    }|                     |           |S )a  Return newly added `w:comment` child of this `w:comments`.

        The returned `w:comment` element is the minimum valid value, having a `w:id` value unique
        within the existing comments and the required `w:author` attribute present but set to the
        empty string. It's content is limited to a single run containing the necessary annotation
        reference but no text. Content is added by adding runs to this first paragraph and by
        adding additional paragraphs as needed.
        z<w:comment wz w:id="z" w:author="">  <w:p>    <w:pPr>      <w:pStyle w:val="CommentText"/>    </w:pPr>    <w:r>      <w:rPr>        <w:rStyle w:val="CommentReference"/>      </w:rPr>      <w:annotationRef/>    </w:r>  </w:p></w:comment>)_next_available_comment_idr   r   r   r   append)selfnext_idcomments      j/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/docx/oxml/comments.pyadd_commentzCT_Comments.add_comment    su     1133 gcll    7       
 
$ 	G    
comment_idintCT_Comment | Nonec                L    |                      d| d          }|r|d         ndS )zRReturn the `w:comment` element identified by `comment_id`, or |None| if not found.z(./w:comment[@w:id='z'])[1]r   Nxpath)r   r!   comment_elmss      r   get_comment_by_idzCT_Comments.get_comment_by_id?   s2    zz"K"K"K"KLL".8|AD8r    c                    d |                      d          D             }t          |d          dz   }|dk    r|S t          t          |                    D ]\  }}||k    r|c S t	          |          S )an  The next available comment id.

        According to the schema, this can be any positive integer, as big as you like, and the
        default mechanism is to use `max() + 1`. However, if that yields a value larger than will
        fit in a 32-bit signed integer, we take a more deliberate approach to use the first
        ununsed integer starting from 0.
        c                ,    g | ]}t          |          S  )r"   ).0xs     r   
<listcomp>z:CT_Comments._next_available_comment_id.<locals>.<listcomp>L   s    DDDqCFFDDDr    z./w:comment/@w:id)default   i)r&   max	enumeratesortedlen)r   used_idsr   expectedactuals        r   r   z&CT_Comments._next_available_comment_idD   s     EDDJJ/B$C$CDDDh+++a/iN !*&*:*: ; ; 	  	 Hf6!! " 8}}r    N)r   r   )r!   r"   r   r#   )r   r"   )
__name__
__module____qualname____doc____annotations__r   r   r   r(   r   r+   r    r   r   r      sy           "!!!j%%G   >9 9 9 9
     r    r   c                     e Zd ZU dZ ede          Zded<    ede          Z	ded<    e
de          Zd	ed
<    e
de          Zded<    edd          Z edd          Zded<   ded<   ded<   ded<   edd            ZdS )r   aQ  `w:comment` element, representing a single comment.

    A comment is a so-called "story" and can contain paragraphs and tables much like a table-cell.
    While probably most often used for a single sentence or phrase, a comment can contain rich
    content, including multiple rich-text paragraphs, hyperlinks, images, and tables.
    zw:idr"   idzw:authorstrauthorz
w:initialsz
str | Noneinitialszw:datezdt.datetime | Nonedatezw:pr+   )
successorszw:tblzCallable[[], CT_P]add_pz
list[CT_P]p_lstzlist[CT_Tbl]tbl_lstzCallable[[CT_Tbl], CT_Tbl]_insert_tblr   list[CT_P | CT_Tbl]c                ,    |                      d          S )z8Generate all `w:p` and `w:tbl` elements in this comment.z./w:p | ./w:tblr%   )r   s    r   inner_content_elementsz!CT_Comment.inner_content_elementsy   s     zz+,,,r    N)r   rI   )r9   r:   r;   r<   r   r
   r?   r=   r   rA   r   rB   r	   rC   r   ptblpropertyrK   r+   r    r   r   r   [   s1           (899B9999##J	::F::::,,i H      10+   D     	
5R(((A
*W
,
,
,C ++++- - - X- - -r    r   )r<   
__future__r   datetimedttypingr   r   r   docx.oxml.nsr   docx.oxml.parserr   docx.oxml.simpletypesr	   r
   r   docx.oxml.xmlchemyr   r   r   r   docx.oxml.tabler   docx.oxml.text.paragraphr   r   r   r+   r    r   <module>rY      s@   : : " " " " " "     0 0 0 0 0 0 0 0 0 0             & & & & & & J J J J J J J J J J ` ` ` ` ` ` ` ` ` ` ` ` .&&&&&&------F F F F F/ F F FR!- !- !- !- !- !- !- !- !- !-r    