<?php

$events = $this->getParam('events', []);
$patterns = [];

foreach ($events as $name => $event) {
    foreach ($event as $key => $value) {
        if (!\str_starts_with($key, '$')) {
            if (!($value['$resource'] ?? false)) {
                $patterns[] = "{$name}.{$key}";
            } else {
                foreach ($value as $key2 => $value2) {
                    if (!\str_starts_with($key2, '$')) {
                        if (!($value2['$resource'] ?? false)) {
                            $patterns[] = "{$key}.{$key2}";
                        }
                    }
                }
            }
        }
    }
}

?>

<div class="cover margin-bottom-large">
    <h1 class="zone xl margin-bottom-large">
        <a data-ls-attrs="href=/console/home?project={{router.params.project}}" class="back text-size-small link-return-animation--start"><i class="icon-left-open"></i> Home</a>
        <br />

        <span>Webhooks</span>
    </h1>
</div>

<div class="zone xl"
    data-service="projects.listWebhooks"
    data-scope="console"
    data-event="load,projects.createWebhook,projects.updateWebhook,projects.deleteWebhook"
    data-name="console-webhooks"
    data-param-project-id="{{router.params.project}}"
    data-success="trigger"
    data-success-param-trigger-events="projects.listWebhooks">

    <div data-ls-if="0 == {{console-webhooks.total}} || undefined == {{console-webhooks.total}}" class="box margin-top margin-bottom">
        <h3 class="margin-bottom-small text-bold">No Webhooks Found</h3>

        <p class="margin-bottom-no">You haven't created any webhooks for your project yet.</p>
    </div>

    <div class="box margin-bottom" data-ls-if="0 != {{console-webhooks.total}}">
        <ul data-ls-loop="console-webhooks.webhooks" data-ls-as="webhook" class="list">
            <li class="clear">
                <a data-ls-attrs="href=/console/webhooks/webhook?project={{router.params.project}}&id={{webhook.$id}}" class="button reverse pull-end margin-end">Manage</a>

                <span data-ls-bind="{{webhook.name}}"></span> &nbsp; (<span data-ls-bind="{{webhook.events.length}}"></span> events)
                <span data-ls-if="false === {{webhook.security}}">
                    &nbsp; <small class="text-danger">(SSL/TLS Disabled)</small>
                </span>
                <div class="margin-top-tiny">
                    <a data-ls-attrs="href={{webhook.url}}" data-ls-bind="{{webhook.url}}" target="_blank" class="text-one-liner"></a>
                </div>
            </li>
        </ul>
    </div>
    <a data-ls-attrs="href=/console/webhooks/webhook/new?project={{router.params.project}}" class="button">Add Webhook</a>
</div>
