# This file is part of RinohType, the Python document preparation system.
#
# Copyright (c) Brecht Machiels.
#
# Use of this source code is subject to the terms of the GNU Affero General
# Public License v3. See the LICENSE file or http://www.gnu.org/licenses/.


from ...decoration import Framed
from ...flowable import DummyFlowable, PageBreak
from ...paragraph import Paragraph
from ...structure import DefinitionList, DefinitionTerm
from ...text import SingleStyledText
from ..rst import BodyElement, InlineElement, GroupingElement
from ..rst.nodes import AdmonitionBase, Strong, Inline


__all__ = ['Compact_Paragraph', 'Index', 'SeeAlso', 'Glossary', 'Start_of_File',
           'Todo_Node', 'HighlightLang', 'Literal_Strong',
           'Desc', 'Desc_Signature', 'Desc_Name', 'Desc_AddName',
           'Desc_ParameterList', 'Desc_Parameter', 'Desc_Optional',
           'Desc_Content', 'VersionModified', 'Tabular_Col_Spec',
           'AutoSummary_Table']


class Compact_Paragraph(GroupingElement):
    pass


class Index(BodyElement, InlineElement):
    def build_styled_text(self):
        return SingleStyledText('')

    def build_flowable(self):
        return DummyFlowable()


class SeeAlso(AdmonitionBase):
    title = 'See also'


class VersionModified(GroupingElement):
    pass


class Glossary(GroupingElement):
    pass


class Start_of_File(GroupingElement):
    def build_flowable(self, **kwargs):
        return super().build_flowable(id=self.get('docname'), **kwargs)


class Todo_Node(GroupingElement):
    def flowable(self):
        return Framed(super().flowable())


class HighlightLang(BodyElement):
    def build_flowable(self):
        return DummyFlowable()


class Literal_Strong(Strong):
    pass


class Desc(BodyElement):
    def build_flowable(self):
        return DefinitionList([(self.desc_signature.flowable(),
                                self.desc_content.flowable())])


class Desc_Signature(BodyElement):
    def build_flowable(self):
        return DefinitionTerm([child.styled_text()
                               for child in self.getchildren()])


class Desc_Name(Inline):
    pass


class Desc_AddName(Inline):
    pass


class Desc_ParameterList(InlineElement):
    def build_styled_text(self):
        return '(' + self.process_content() + ')'


class Desc_Parameter(Inline):
    pass


class Desc_Optional(InlineElement):
    def build_styled_text(self):
        return '[, ' + self.process_content() + ']'


class Desc_Content(GroupingElement):
    pass


class Tabular_Col_Spec(BodyElement):
    def build_flowable(self):
        return DummyFlowable()


class AutoSummary_Table(GroupingElement):
    def build_flowable(self):
        return DummyFlowable()

@@ -725,16 +725,24 @@
 Strong',
+ 'Desc',
 %0A       
@@ -744,24 +744,16 @@
         
- 'Desc',
  'Desc_S
@@ -791,27 +791,16 @@
 ddName',
-%0A          
  'Desc_P
@@ -813,16 +813,27 @@
 erList',
+%0A          
  'Desc_P
@@ -859,27 +859,35 @@
 tional',
-%0A          
+ 'Desc_Annotation',
  'Desc_C
@@ -894,16 +894,27 @@
 ontent',
+%0A          
  'Versio
@@ -944,27 +944,16 @@
 l_Spec',
-%0A          
  'AutoSu
@@ -2467,24 +2467,66 @@
 t() + '%5D'%0A%0A%0A
+class Desc_Annotation(Inline):%0A    pass%0A%0A%0A
 class Desc_C

Support the Sphinx desc_annotation node