@extends('layout.index', [
	'title' => __('User.title'),
	'subtitle' => __('User.list'),
	'breadcrumb' => [
		__('User.title') => 'Admin.Core.Auth.User.index',
	]
])

@include('load.form.select2')

@section('content')

	@component('components.card')
		@include('components.datatable', ['route' => route('Admin.Core.Auth.User.index'), 'model' => 'users', 'callback' => 'handleUser();', 'create_callback' => 'UserCreate();', 'edit_callback' => 'UserEdit(id);', 'with_filters' => true])
	@endcomponent

	@component('components.layout.modal-filters', ['title' => 'Filters', 'id' => 'modal-users-filters'])
		@include('admin.Core.Auth.User.partials.filters', ['model' => 'users'])
	@endcomponent

@endsection

@include('load.layout.chevron')
@include('load.layout.modal')
@include('load.form.toggle')
@include('load.form.upload.upload')

@push('js')
	<script>

		function handleUser() {
			initToggle("{{ route('Admin.Core.Auth.User.toggleActive') }}");
		}

		function UserCreate() {
			var url_open = "{{ route('Admin.Core.Auth.User.modalCreate') }}";
			var url_save = "{{ route('Admin.Core.Auth.User.storeAjax') }}";
			openModal("{{ __('user') }}", '#user-form', url_open, url_save, "UserRefresh();");
		}

		function UserEdit(id) {
			var url_open = "{{ route('Admin.Core.Auth.User.modalEdit') }}/" + id;
			var url_save = "{{ route('Admin.Core.Auth.User.storeAjax') }}";
			openModal("{{ __('user') }}", '#user-form', url_open, url_save, "UserRefresh();");
		}

		function UserRefresh() {
			reloadDatatable('users');
			handleUser();
		}

		$(document).ready(function () {
			initSelect2();
		});

	</script>
@endpush
