<x-admin.layout title="Releases">
    <div class="grid two">
        <div class="card">
            <h2>Create Release</h2>
            <form method="post" action="{{ route('admin.releases.store') }}">
                @csrf
                <label>Product</label><select name="product_id" required>@foreach ($products as $product)<option value="{{ $product->id }}">{{ $product->name }}</option>@endforeach</select>
                <label>Version</label><input name="version" required placeholder="1.0.0">
                <label>Channel</label><input name="channel" value="stable" required>
                <label>File URL</label><input name="file_url" type="url" required>
                <label>SHA256</label><input name="sha256">
                <label>Min Version</label><input name="min_version">
                <label>Published At</label><input name="published_at" type="datetime-local">
                <label><input name="is_required" type="checkbox" value="1" style="width:auto"> Required update</label>
                <button type="submit">Create</button>
            </form>
        </div>
        <div class="card">
            <h2>Releases</h2>
            <div class="table-wrap">
                <table><thead><tr><th>Product</th><th>Release</th><th>File</th><th>Published</th><th>Actions</th></tr></thead><tbody>
                    @foreach ($releases as $release)
                        <tr>
                            <td>{{ $release->product?->name }}</td>
                            <td colspan="4">
                                <form method="post" action="{{ route('admin.releases.update', $release) }}" class="admin-inline-form">
                                    @csrf
                                    @method('PATCH')
                                    <input name="version" value="{{ $release->version }}" required>
                                    <input name="channel" value="{{ $release->channel }}" required>
                                    <input name="file_url" type="url" value="{{ $release->file_url }}" required>
                                    <input name="sha256" value="{{ $release->sha256 }}" placeholder="sha256">
                                    <input name="min_version" value="{{ $release->min_version }}" placeholder="min version">
                                    <input name="published_at" type="datetime-local" value="{{ $release->published_at?->format('Y-m-d\TH:i') }}">
                                    <label><input name="is_required" type="checkbox" value="1" style="width:auto" @checked($release->is_required)> Required</label>
                                    <button type="submit">Save</button>
                                </form>
                                <form method="post" action="{{ route('admin.releases.destroy', $release) }}" onsubmit="return confirm('Delete release?')">
                                    @csrf
                                    @method('DELETE')
                                    <button class="button danger" type="submit">Delete</button>
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody></table>
            </div>
            {{ $releases->links() }}
        </div>
    </div>
</x-admin.layout>
