# -*- coding: utf-8 -*-

# Copyright(C) 2012-2020  Budget Insight
#
# This file is part of a woob module.
#
# This woob module is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This woob module is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this woob module. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from woob.browser.filters.standard import (
    CleanText,
)
from woob.browser.pages import HTMLPage


class AuthorizePage(HTMLPage):
    def redirect(self):
        # just one form on this page, so get_form() should work but it's better to put a more restrictive xpath
        form = self.get_form(xpath='//form[@action="/confirm-redirect-client"]')
        form.submit()


class AmeliLoginPage(HTMLPage):
    def login(self, username, password):
        # CAUTION, form id, username and password keys are not the same than the one of standard ameli login page
        form = self.get_form(id='connexion_form')
        form['j_username'] = username
        form['j_password'] = password
        form.submit()


class WrongPassAmeliLoginPage(HTMLPage):
    def get_error_message(self):
        return CleanText('//div[@id="divErreur"]')(self.doc)
