<?php
    $client = $client ?? null;
    $lockClient = isset($lockClient) ? $lockClient : request('lock_client');
    $lockedClientId = isset($lockedClientId) ? $lockedClientId : ($lockClient ? request('client_id') : null);
    $lockedClientText = isset($lockedClientText) ? $lockedClientText : ($lockClient ? request('client_text') : null);
?>
<div class="box box-primary">
        <div class="box-body">
            <div class="row">
                <div class="col-md-4">
                    <div class="form-group">
                        <label>العميل</label>
                        <?php
                            $per = $client ? ($client->client ?? '') : '';
                            $lockedClientDisplay = $lockedClientText ?: (isset($per) && !empty($per) ? ($per->id . ' - ' . $per->name . ' - ' . $per->mobile) : '');
                        ?>
                        <?php if($lockedClientId): ?>
                            <input type="hidden" name="client_id" value="<?php echo e($lockedClientId); ?>">
                            <input type="text" id="lockedClientName" class="form-control" value="<?php echo e($lockedClientDisplay); ?>" readonly>
                        <?php else: ?>
                            <div class="input-group">
                                <select required data-url="<?php echo e(route('getClientsList')); ?>" name="client_id" id="personList"
                                    class="form-control select2AjaxRequest">
                                    <option value="">--- إختر ---</option>
                                    <?php if(isset($per) && !empty($per)): ?>
                                        <option selected value="<?php echo e($per->id); ?>">
                                            <?php echo e($per->id . ' - ' . $per->name . ' - ' . $per->mobile); ?>

                                        </option>
                                    <?php endif; ?>
                                </select>
                                <div class="input-group-addon no-print" style="padding: 2px 5px;">
                                    <a href="<?php echo e(route('clients.create', ['req' => 'ajax'])); ?>" class="external"
                                        data-toggle="modal" data-target="#myModal">
                                        <i class="fa fa-2x fa-plus-circle"></i>
                                    </a>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label>ماركة السيارة</label>
                        <select style="width: 100%" id="brandList" name="car_brand" data-placeholder="إختر الماركة"
                            data-url="<?php echo e(route('getbrands')); ?>" class="form-control select2AjaxRequest">
                            <?php if(isset($client->car_brand)): ?>
                                <option selected value="<?php echo e($client->car_brand ?? ''); ?>">
                                    <?php echo e($client->car_brand ?? ''); ?>

                                </option>
                            <?php endif; ?>
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label>موديل السيارة</label>
                        <select style="width: 100%" id="modelSelect2" name="model" data-placeholder="إختر الموديل"
                            data-url="<?php echo e(route('getmodels')); ?>" class="form-control">
                            <?php if(isset($client->model)): ?>
                                <option selected value="<?php echo e($client->model ?? ''); ?>">
                                    <?php echo e($client->model ?? ''); ?>

                                </option>
                            <?php endif; ?>
                        </select>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-group customOptions">
                        <label>اللون</label>
                        <select style="width: 100%" name="color" data-placeholder="إختر اللون"
                            data-url="<?php echo e(route('getcolors')); ?>" class="form-control select2AjaxRequest">
                            <?php if(isset($client->color)): ?>
                                <option selected value="<?php echo e($client->color ?? ''); ?>">
                                    <?php echo e($client->color ?? ''); ?>

                                </option>
                            <?php endif; ?>
                        </select>
                    </div>
                </div>

                <div class="col-md-4">
                    <div class="form-group">
                        <label for="address">رقم الشاسيه</label>
                        <input name="chassis_no" value="<?php echo e($client->chassis_no ?? ''); ?>" type="text"
                            class="form-control">
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label>رقم اللوحة</label>
                        <input name="car_number" value="<?php echo e($client->car_number ?? ''); ?>" type="text"
                            class="form-control">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-2">
                    <div class="form-group">
                        <label>سنة الصنع</label>
                        <input name="year" value="<?php echo e($client->year ?? ''); ?>" type="number" min="1900" max="2099"
                            placeholder="2024" class="form-control">
                    </div>
                </div>
                <div class="col-md-5">
                    <div class="form-group">
                        <label>اسم من أحضر السيارة</label>
                        <input name="delivery_name" value="<?php echo e($client->delivery_name ?? ''); ?>" type="text"
                            class="form-control">
                    </div>
                </div>
                <div class="col-md-5">
                    <div class="form-group">
                        <label>جوال من أحضر السيارة</label>
                        <input name="delivery_mobile" value="<?php echo e($client->delivery_mobile ?? ''); ?>" type="text"
                            class="form-control">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label>مرفقات</label>
                        <input multiple name="attachments[]" type="file" class="form-control ">
                        <?php if(isset($client) && $client): ?>
                            <?php $__currentLoopData = method_exists($client, 'getMedia') ? $client->getMedia('attachments') : collect(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $file): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="col-md-2 imageContainer">
                                    <?php
                                        $filepath = $file->getUrl();
                                        $extension = $file->mime_type;
                                    ?>
                                    <?php if(in_array($extension, ['image/jpeg', 'image/png'])): ?>
                                        <img style="width: 100px;" src="<?php echo e($filepath); ?>">
                                    <?php else: ?>
                                        <a style="margin-bottom: 5px;" target="_blank" href="<?php echo e($filepath); ?>"
                                            class="btn btn-sm btn-warning">View </a>
                                    <?php endif; ?>
                                    <a class="btn btn-danger btn-sm deleteImg" rel="<?php echo e($file->id); ?>"
                                        href="#"><i class="fa fa-trash close_button"></i></a>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        <label for="note">تفاصيل وملاحظات</label>
                        <textarea name="note" class="form-control"><?php echo e($client->note ?? ''); ?></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer">
            <button type="submit" class="btn btn-primary">حفظ</button>
            <?php if(request('req') === 'ajax' || request('lock_client')): ?>
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">تراجع</button>
            <?php endif; ?>
        </div>
    </div>
    <!-- /.box -->
    <?php $__env->startPush('js'); ?>
        <script>
            $('.select2AjaxRequest').select2({
                ajax: {
                    url: function() {
                        return $(this).attr('data-url');
                    },
                    dataType: 'json',
                    data: function(params) {
                        return {
                            term: params.term
                        };
                    },
                    processResults: function(response) {
                        return {
                            results: response
                        };
                    },
                    cache: true,
                    minimumInputLength: 1,
                }
            });
            $('#modelSelect2').select2({
                placeholder: "إختر الموديل",
                ajax: {
                    url: function() {
                        return $(this).attr('data-url');
                    },
                    dataType: 'json',
                    data: function(params) {
                        return {
                            term: params.term,
                            model: $('#brandList').val(),
                        };
                    },
                    processResults: function(response) {
                        return {
                            results: response
                        };
                    },
                    cache: true,
                }
            });
            $('body').on('submit', 'form', function(e) {
                var $btn = $(this).find(':submit');
                if ($btn.hasClass('disabled')) return false;
                $btn.attr('data-loading-text', "<i class='fa fa-circle-o-notch fa-spin'></i> <?php echo app('translator')->get('front.Saving ...'); ?>");
                $btn.button('loading');
                setTimeout(function() {
                    $btn.button('reset');
                }, 3000);
            });
        </script>
    <?php $__env->stopPush(); ?><?php /**PATH /home/mwarsha2023/public_html/test4.mwarsha.com/resources/views/clientcars/_form.blade.php ENDPATH**/ ?>