'''
Created on 01-Apr-2021
@author: bthakur
'''

from ..helper import BaseHelper
from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
        
class ActivityManager(BaseManager):
    '''
    Misc activities for students, with external links
    
    Example:
        ke = ActivityManager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printProblemTypes()
        
    '''    
    _OPR_TYPE_COUNT = 10
    
    def __new__(cls, *args, **kwargs):
        instance = super(ActivityManager, cls).__new__(cls, *args, **kwargs)
        for base_class in ActivityManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        self.base_helper = BaseHelper(**kwargs)
        pass
    


    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_problem_mobius_strip',
            '_problem_four_color_theorem',
            '_problem_right_angle_similar_triangles',
            '_problem_triangle_with_angles_more_than_2_pi',
            ])
        pass

    def _problem_mobius_strip(self, *args, **kwargs):
                
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        statement = f"""
        Do the followings:
        <ul>
            <li>
                1. Create a mobius strip
            </li>
            <li>
                2. Create two entangled hearts from mobius strip
            </li>
        </ul>
        """
        problemTemplate.add_problem(statement.strip(), "text/html",
                                    add_html_line_break = False)
        
        soln_s = f"""
        Resources:
        <ol>
            <li>
                <a target='_blank' href='https://www.mathscareers.org.uk/valentines-maths-mobius-hearts/'>
                Valentine’s Day Maths – Linked Möbius Hearts
                </a>
            </li>
            <li>
                <a target='_blank' href='https://www.mathscareers.org.uk/just-one-side-gets-twist/'>
                What has just one side and gets in a twist?
                </a>
            </li>
        </ol>
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)


        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html',
                                     add_html_line_break = False)
        
        return problemTemplate

    def _problem_four_color_theorem(self, *args, **kwargs):
                
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        statement = f"""
        Take picture of a map and color all different countries of a region
        with minimum number of colors. How many colors you need?
        
        """
        problemTemplate.add_problem(statement.strip(), 'text/html',
                                     add_html_line_break = False)

        soln_s = f"""
        It is called Four Colour Theorem. Try to draw a network map of all countries
        you are coloring. 
        <br /><br />
        Draw a network graph of countries with edges for direct contact.
        Color the nodes with different colors. You will find that all you need
        is four different colors.
        <br /><br />
        <h4>Resources:</h4>
        <ol>
            <li>
                <a target='_blank' href='https://en.wikipedia.org/wiki/Four_color_theorem'>
                    Four color theorem - Wikipedia
                </a>
            </li>
        </ol>
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)


        answer_s = f"""
        You need four colors.
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html',
                                     add_html_line_break = False)
        
        return problemTemplate

    def _problem_right_angle_similar_triangles(self, *args, **kwargs):
                
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        statement = f"""
        If you create two right angled triangles by dividing a right angled triangle,
        all triangles are similar. Use a rectangular piece of paper to show it.
        """
        problemTemplate.add_problem(statement.strip(), "text/html",
                                     add_html_line_break = False)
        
        soln_s = f"""
        Take a rectangular piece of paper and divide it into two 
        identical triangles by cutting it diagonally. 
        <br/>
        Take one of the triangles and from the right angle, draw a normal (or altitude) to 
        the hypotenuse. Cut along this normal line to get two triangles.
        <br/>
        Now, you have three triangles, Arrange them one over another
        to show that they are similar.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)


        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html',
                                     add_html_line_break = False)
        
        return problemTemplate


    def _problem_triangle_with_angles_more_than_2_pi(self, *args, **kwargs):
                
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        statement = f"""
        How can you show that triangles can have its sum of angles more than pi.
        """
        problemTemplate.add_problem(statement.strip(), "text/html",
                                     add_html_line_break = False)
        
        soln_s = f"""
        Take a ball and draw a triangle from pole (imagine one).
        
        <br /><br />
        <h4>Resources:</h4>
        <ol>
            <li>
                <a target='_blank' href='https://www.youtube.com/watch?v=_xpgOOXYOdE'>
                    Triangle on Sphere
                </a>
            </li>
        </ol>
        
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)


        answer_s = soln_s
        problemTemplate.add_answer(answer_s.strip(), 'text/html',
                                     add_html_line_break = False)
        
        return problemTemplate

    def _problem_TEMPLATE(self, *args, **kwargs):
                
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')
        
        statement = f"""
        """
        problemTemplate.add_problem(statement.strip(), "text/html",
                                     add_html_line_break = False)
        
        soln_s = f"""
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html',
                                     add_html_line_break = False)


        answer_s = f""""""
        problemTemplate.add_answer(answer_s.strip(), 'text/html',
                                     add_html_line_break = False)
        
        return problemTemplate

