<div class="p-5 sm:p-6" wire:init="load">
    <div class="flex items-start gap-3.5">
        <span class="grid h-10 w-10 shrink-0 place-items-center rounded-md border border-accent/30 bg-accent/10 text-accent-text">
            <x-icon name="file" class="h-5 w-5" />
        </span>
        <div class="min-w-0 flex-1">
            <h2 class="truncate font-display text-base font-semibold text-ink" title="{{ $name }}">{{ $name }}</h2>
            <p class="mt-1 truncate font-mono text-[11px] text-ink-3" title="{{ $path }}">{{ $path }}</p>
        </div>
    </div>

    <div class="mt-4">
        @if (! $loaded)
            <div class="space-y-2"><x-skeleton class="h-3 w-full" /><x-skeleton class="h-3 w-5/6" /><x-skeleton class="h-3 w-2/3" /><x-skeleton class="h-3 w-3/4" /></div>
        @elseif ($error)
            <p class="flex items-center gap-1.5 font-mono text-[11px] text-offline"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $error }}</p>
        @elseif ($tooBig)
            <p class="flex items-center gap-1.5 font-mono text-[11px] text-warning"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ $this->isImage() ? __('modals.file_editor.image_too_big') : __('modals.file_editor.too_big') }}</p>
        @elseif ($this->isImage())
            <div class="overflow-hidden rounded-md border border-line bg-void p-3">
                <img src="{{ $dataUri }}" alt="{{ $name }}" class="mx-auto max-h-[70vh] w-full object-contain" />
            </div>
        @elseif ($binary)
            <p class="flex items-center gap-1.5 font-mono text-[11px] text-warning"><x-icon name="alert" class="h-3.5 w-3.5 shrink-0" />{{ __('modals.file_editor.binary') }}</p>
        @else
            <textarea wire:model="content" rows="14" spellcheck="false"
                class="w-full resize-none rounded-md border border-line bg-void px-3 py-2.5 font-mono text-[11px] leading-relaxed text-ink-2 focus:border-accent/40 focus:outline-none"></textarea>
        @endif
    </div>

    <div class="mt-5 flex items-center justify-end gap-2">
        <x-btn variant="secondary" wire:click="$dispatch('closeModal')">{{ __('common.close') }}</x-btn>
        @if ($loaded && ! $error && ! $tooBig && ! $binary && ! $this->isImage())
            @can('operate')
                <x-btn variant="primary" wire:click="save" wire:target="save" wire:loading.attr="disabled">
                    <svg wire:loading wire:target="save" class="h-3.5 w-3.5 animate-spin" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" aria-hidden="true"><path d="M21 12a9 9 0 1 1-6.219-8.56" stroke-linecap="round" /></svg>
                    {{ __('common.save') }}
                </x-btn>
            @endcan
        @endif
    </div>
</div>
