o
    ýÞh0  ã                   @  s°   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rFdd	lmZ dd
lmZ G dd„ deƒZG d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                   @  s@   e Zd ZU dZded< edƒZddd„Zddd„Zd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                 C  s6   |   ¡ }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Úcomment© r   úR/var/www/html/premium_crap/venv/lib/python3.10/site-packages/docx/oxml/comments.pyÚadd_comment    s   	ÿþ
zCT_Comments.add_commentÚ
comment_idÚintúCT_Comment | Nonec                 C  s"   |   d|› d�¡}|r|d S 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_elmsr   r   r   Úget_comment_by_id?   s   zCT_Comments.get_comment_by_idc                 C  s^   dd„ |   d¡D ƒ}t|dd�d }|dkr|S tt|ƒƒD ]\}}||kr*|  S q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                 S  s   g | ]}t |ƒ‘qS r   )r   )Ú.0Úxr   r   r   Ú
<listcomp>L   s    z:CT_Comments._next_available_comment_id.<locals>.<listcomp>z./w:comment/@w:idéÿÿÿÿ)Údefaulté   iÿÿÿ)r"   ÚmaxÚ	enumerateÚsortedÚlen)r   Úused_idsr   ÚexpectedÚactualr   r   r   r   D   s   ÿz&CT_Comments._next_available_comment_idN)r   r   )r   r   r   r    )r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r   r$   r   r   r   r   r   r      s   
 	

r   c                   @  s    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d�Zeddd�Zded< ded< ded< ded< ed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                 C  s
   |   d¡S )z8Generate all `w:p` and `w:tbl` elements in this comment.z./w:p | ./w:tblr!   )r   r   r   r   Úinner_content_elementsy   s   
z!CT_Comment.inner_content_elementsN)r   rA   )r2   r3   r4   r5   r   r	   r7   r6   r
   r9   r   r:   r   r;   r   ÚpÚtblÚpropertyrB   r   r   r   r   r   [   s$   
 ÿÿr   )r5   Ú
__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   r   Ú<module>   s    I