#!/usr/bin/env python
# coding=utf8
from flask import Blueprint

try:
    from wtforms.fields import HiddenField

    def is_hidden_field_filter(field):
        return isinstance(field, HiddenField)
except ImportError:
    def HiddenField():
        pass

    def is_hidden_field_filter(field):
        raise RuntimeError('WTForms is not installed.')


class JqueryUiBootstrap(object):
    def __init__(self, app=None):
        if app is not None:
            self.init_app(app)

    def init_app(self, app):
        app.config.setdefault('BOOTSTRAP_HTML5_SHIM', True)
        app.config.setdefault('BOOTSTRAP_GOOGLE_ANALYTICS_ACCOUNT', None)

        blueprint = Blueprint(
            'jquery_ui_bootstrap',
            __name__,
            template_folder='templates',
            static_folder='static',
            static_url_path=app.static_url_path + '/jquery_ui_bootstrap')

        app.register_blueprint(blueprint)

        app.jinja_env.filters['bootstrap_is_hidden_field'] =\
            is_hidden_field_filter
