<?php /** @var \App\Models\Category $category */ ?>
<div class="languages-selector form-group level" x-data="{
    search: '',
    selected: @js((array) $selected),
    toggle(value){
        const i = this.selected.indexOf(value);
        i === -1 ? this.selected.push(value) : this.selected.splice(i,1);
    },
    valueSelect(value){
        return this.selected.includes(value);
    },
    get count(){ return this.selected.length; }
}">
    <div class="language-search">
        <i data-lucide="search"></i>
        <input type="text" x-model="search" placeholder="Search a category" autocomplete="off">
        <button class="btn" type="button" x-show="search !== ''" @click="search = ''" x-cloak>
            <i data-lucide="x"></i>
        </button>
    </div>
    <div class="language-list" id="languages-group">
        @foreach( $categories as $category )
            <label class="language-item" x-show="'{{ strtolower($category->name) }}'.includes(search.toLowerCase())">
                <input type="checkbox" name="categories[]" value="{{ $category->id }}" x-model="selected" :value="{{ $category->id }}" {{ in_array($category->id, $selected) ? 'checked' : '' }}> {{ $category->name }}
            </label>
        @endforeach
    </div>

</div>
