<div>
    <x-slot:title>
        {{ data_get_str($server, 'name')->limit(10) }} > Log Drains | Coolify
    </x-slot>
    <livewire:server.navbar :server="$server" />
    <div class="flex flex-col h-full gap-8 sm:flex-row">
        <x-server.sidebar :server="$server" activeMenu="log-drains" />
        <div class="w-full">
            @if ($server->isFunctional())
                <div class="flex gap-2 items-center">
                    <h2>Log Drains</h2>
                    <x-loading wire:target="toggleLogDrain" wire:loading.delay />
                </div>
                <div>Sends service logs to 3rd party tools.</div>
                <div class="flex flex-col gap-4 pt-4">
                    <div class="p-4 border dark:border-coolgray-300 border-neutral-200">
                        <form wire:submit='submit("newrelic")' class="flex flex-col">
                            <div class="flex items-center gap-2">
                                <h3>New Relic</h3>
                                @if ($isLogDrainNewRelicEnabled)
                                    <x-forms.button canGate="update" :canResource="$server" type="submit">
                                        Save
                                    </x-forms.button>
                                    <x-forms.button canGate="update" :canResource="$server" wire:click="toggleLogDrain('newrelic')">
                                        Disable New Relic
                                    </x-forms.button>
                                @elseif ($isLogDrainAxiomEnabled || $isLogDrainCustomEnabled)
                                    <x-forms.button disabled>
                                        Enable New Relic
                                    </x-forms.button>
                                @else
                                    <x-forms.button canGate="update" :canResource="$server" isHighlighted wire:click="toggleLogDrain('newrelic')">
                                        Enable New Relic
                                    </x-forms.button>
                                @endif
                            </div>
                            <div class="flex flex-col gap-4">
                                <div class="flex flex-col w-full gap-2 xl:flex-row">
                                    @if ($server->isLogDrainEnabled())
                                        <x-forms.input disabled type="password" required id="logDrainNewRelicLicenseKey"
                                            label="License Key" />
                                        <x-forms.input disabled required id="logDrainNewRelicBaseUri"
                                            placeholder="https://log-api.eu.newrelic.com/log/v1"
                                            helper="For EU use: https://log-api.eu.newrelic.com/log/v1<br>For US use: https://log-api.newrelic.com/log/v1"
                                            label="Endpoint" />
                                    @else
                                        <x-forms.input canGate="update" :canResource="$server" type="password" required
                                            id="logDrainNewRelicLicenseKey" label="License Key" />
                                        <x-forms.input canGate="update" :canResource="$server" required
                                            id="logDrainNewRelicBaseUri"
                                            placeholder="https://log-api.eu.newrelic.com/log/v1"
                                            helper="For EU use: https://log-api.eu.newrelic.com/log/v1<br>For US use: https://log-api.newrelic.com/log/v1"
                                            label="Endpoint" />
                                    @endif
                                </div>
                            </div>
                            <div class="flex justify-end gap-4 pt-6">
                                <x-forms.button canGate="update" :canResource="$server" type="submit">
                                    Save
                                </x-forms.button>
                            </div>
                        </form>

                        <form wire:submit='submit("axiom")' class="flex flex-col">
                            <div class="flex items-center gap-2">
                                <h3>Axiom</h3>
                                @if ($isLogDrainAxiomEnabled)
                                    <x-forms.button canGate="update" :canResource="$server" type="submit">
                                        Save
                                    </x-forms.button>
                                    <x-forms.button canGate="update" :canResource="$server" wire:click="toggleLogDrain('axiom')">
                                        Disable Axiom
                                    </x-forms.button>
                                @elseif ($isLogDrainNewRelicEnabled || $isLogDrainCustomEnabled)
                                    <x-forms.button disabled>
                                        Enable Axiom
                                    </x-forms.button>
                                @else
                                    <x-forms.button canGate="update" :canResource="$server" isHighlighted wire:click="toggleLogDrain('axiom')">
                                        Enable Axiom
                                    </x-forms.button>
                                @endif
                            </div>
                            <div class="flex flex-col gap-4">
                                <div class="flex flex-col w-full gap-2 xl:flex-row">
                                    @if ($server->isLogDrainEnabled())
                                        <x-forms.input disabled type="password" required id="logDrainAxiomApiKey"
                                            label="API Key" />
                                        <x-forms.input disabled required id="logDrainAxiomDatasetName"
                                            label="Dataset Name" />
                                    @else
                                        <x-forms.input canGate="update" :canResource="$server" type="password" required
                                            id="logDrainAxiomApiKey" label="API Key" />
                                        <x-forms.input canGate="update" :canResource="$server" required
                                            id="logDrainAxiomDatasetName" label="Dataset Name" />
                                    @endif
                                </div>
                            </div>
                            <div class="flex justify-end gap-4 pt-6">
                                <x-forms.button canGate="update" :canResource="$server" type="submit">
                                    Save
                                </x-forms.button>
                            </div>
                        </form>
                        <form wire:submit='submit("custom")' class="flex flex-col">
                            <div class="flex items-center gap-2">
                                <h3>Custom FluentBit</h3>
                                @if ($isLogDrainCustomEnabled)
                                    <x-forms.button canGate="update" :canResource="$server" type="submit">
                                        Save
                                    </x-forms.button>
                                    <x-forms.button canGate="update" :canResource="$server" wire:click="toggleLogDrain('custom')">
                                        Disable Custom FluentBit
                                    </x-forms.button>
                                @elseif ($isLogDrainNewRelicEnabled || $isLogDrainAxiomEnabled)
                                    <x-forms.button disabled>
                                        Enable Custom FluentBit
                                    </x-forms.button>
                                @else
                                    <x-forms.button canGate="update" :canResource="$server" isHighlighted wire:click="toggleLogDrain('custom')">
                                        Enable Custom FluentBit
                                    </x-forms.button>
                                @endif
                            </div>
                            <div class="flex flex-col gap-4">
                                @if ($server->isLogDrainEnabled())
                                    <x-forms.textarea disabled rows="6" required id="logDrainCustomConfig"
                                        label="Custom FluentBit Configuration" />
                                    <x-forms.textarea disabled id="logDrainCustomConfigParser"
                                        label="Custom Parser Configuration" />
                                @else
                                    <x-forms.textarea canGate="update" :canResource="$server" rows="6" required
                                        id="logDrainCustomConfig" label="Custom FluentBit Configuration" />
                                    <x-forms.textarea canGate="update" :canResource="$server"
                                        id="logDrainCustomConfigParser" label="Custom Parser Configuration" />
                                @endif

                            </div>
                            <div class="flex justify-end gap-4 pt-6">
                                <x-forms.button canGate="update" :canResource="$server" type="submit">
                                    Save
                                </x-forms.button>
                            </div>
                        </form>

                    </div>
                </div>
            @else
                <div>Server is not validated. Validate first.</div>
            @endif
        </div>
    </div>
</div>
