<tal:block replace="structure context/manage_page_header" />
<tal:block replace="structure context/manage_tabs" />

<style>
    .listing {
        border-collapse: collapse;
    }
    .listing td, .listing th {
        border-width: 1px;
        border-color: gray;
        border-style: solid;
    }
    .tooltip {
        display: none;
    }
    .link-manage-bundles {
        float: right;
    }
</style>
<link rel="stylesheet" type="text/css" media="screen" href="misc_/Naaya/jquery.tooltip.css" />

<div class="link-manage-bundles">
    <a href="./manage_bundle">Manage bundle</a>
</div>

<tal:block define="selected_interface python: request.form.get('interface', 'ITemplate')">
<form action="" method="GET">
    <select name="interface">
        <option value="">Please select interface</option>

        <tal:block repeat="interface view/get_interfaces">
        <option tal:define="interface_name python: view.get_interface_name(interface)"
                tal:attributes="value interface_name;
                                selected python: selected_interface == interface_name;"
                tal:content="interface_name" />
        </tal:block>
    </select>
    <input type="submit" value="Search utilities" />
</form>

<table class="listing"
    tal:define="interface python: view.get_interface_by_name(selected_interface)"
    tal:condition="python: interface is not None">
<tal:block tal:define="managers view/get_managers;
                       utilities_names python: view.get_utilities_names(interface);">
    <thead>
        <tr>
            <th>Name</th>
            <th tal:repeat="manager managers">
                <tal:block define="manager_name python: view.get_manager_name(manager);
                                   manager_class_name python: view.get_manager_class_name(manager)">
                <tal:block content="string:${manager_name}
                                           (${manager_class_name})" />
                <form tal:condition="python:view.is_reloader_available(manager_name)"
                      method="post" action="inspector_reload_bundle">
                    <input type="hidden" name="bundle_name"
                           tal:attributes="value manager_name"/>
                    <input type="submit" value="reload"/>
                </form>
                </tal:block>
            </th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <tr tal:repeat="utility_name utilities_names">
            <tal:block define="utility_registrations python: view.get_utility_registrations(interface, utility_name)">
            <td>
                <span class="utility_name" tal:content="utility_name" />
                <div class="tooltip">
                    <div tal:repeat="ur utility_registrations"
                        tal:content="ur"></div>
                </div>
            </td>
            <td tal:repeat="manager managers">
                <img src="misc_/Naaya/checked" alt="provides" title="provides"
                    tal:condition="python: view.has_utility(manager, utility_registrations)" />
            </td>
            <td>
                <a tal:condition="python: view.can_get_diff(utility_registrations)"
                    tal:attributes="href string:${here/absolute_url}/inspector_diff_view?interface=${selected_interface}&utility=${utility_name}">diff</a>
            </td>
            </tal:block>
        </tr>
    </tbody>
</tal:block>
</table>
</tal:block>

<script type="text/javascript" src="misc_/Naaya/jquery.min.js"></script>
<script type="text/javascript" src="misc_/Naaya/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="misc_/Naaya/jquery.tooltip.min.js"></script>
<script>
$(".utility_name").tooltip({
    bodyHandler: function() {
        return $(this).next().html();
    }
});
</script>

<tal:block replace="structure context/manage_page_footer" />
