 @extends('admin.layouts.main-layout')
@section("css")
        
@endsection
@section("content")
            <div id="top" class="sa-app__body">
                <div class="mx-sm-2 px-2 px-sm-3 px-xxl-4 pb-6">
                    <div class="container">
                        <div class="py-5">
                            <div class="row g-4 align-items-center">
                                <div class="col">
                                    <nav class="mb-2" aria-label="breadcrumb">
                                        <ol class="breadcrumb breadcrumb-sa-simple">

                                            <li class="breadcrumb-item active" aria-current="page"></li>
                                        </ol>
                                    </nav>
                                    <h1 class="h3 m-0">Edit Refrence</h1>
                                </div>
                            </div>
                        </div>
                        <div class="sa-entity-layout" data-sa-container-query="{&quot;920&quot;:&quot;sa-entity-layout--size--md&quot;,&quot;1100&quot;:&quot;sa-entity-layout--size--lg&quot;}">
                            <div class="sa-entity-layout__body">
                                <div class="sa-entity-layout__main">
                                    <div class="card">
                                        <div class="card-body p-5">

                                            <form method="post" action="{{ url('admin/refrence/'.$detail->id) }}" onsubmit="return validateForm('addsstatus')" class="addsstatus" autocomplete="off" enctype="multipart/form-data">
                                                @csrf
                                                {{ method_field('PATCH') }}
                                                </br>

                                                <div class="row mb-3">
                                                    <label for="Name" class="col-sm-3 col-form-label">User Id</label>
                                                    <div class="row mb-3">
                                                    <label for="Name" class="col-sm-3 col-form-label">User</label>
                                                    <div >
                                                        <select class="form-control select2 input-mandatory" name="user_id">
                                                            <option value="">---Select User---</option>
                                                            @foreach($detail as $caste)
                                                                <option value="{{$caste->id}}">{{$caste->name}}</option>
                                                            @endforeach      
                                                            </select>
                                                            @if($errors->has('user_id'))
                                                                <span class="text-danger">{{ $errors->first('user_id') }}</span>
                                                            @endif
                                                        </div>
                                                </div>
                                                </div>
                                                @if($errors->has('user_id'))
                                                    <span class="text-danger">{{ $errors->first('user_id') }}</span>
                                                @endif

                                                <div class="row mb-3">
                                                    <label for="Name" class="col-sm-3 col-form-label">Code</label>
                                                    <div class="col-sm-9">
                                                        <input type="text" class="form-control input-mandatory" id="codes" name="codes" value="{{$detail->codes}}" placeholder="Enter Name" maxlength="30">
                                                    </div>
                                                </div>
                                                @if($errors->has('codes'))
                                                    <span class="text-danger">{{ $errors->first('codes') }}</span>
                                                @endif

                                                </br>
                                                <button type="submit" style="float:right" class="btn btn-info px-5">Save</button>
                                                <a href="{{url('admin/lucky')}}" style="float:right;margin-right: 12px;" class="btn btn-danger reset-btn">Cancel</a>
                                        </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div><!-- sa-app__body / end --><!-- sa-app__footer -->
            @endsection
@section("script")
@include('admin.refrence.js')
@endsection

<script>
    $(document).ready(function() {
        var selectedImageURL = "{{ isset($detail->image) ? url($detail->image) : ''}}";
        if (selectedImageURL) {
            $('#s_photo').attr('src', selectedImageURL);
            $("#s_photo").css("display", "block");
        }
    });

    // Handle changes to the photo input
    $("#p_image").change(function() {
        readURLphoto(this);
    });

    function readURLphoto(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            
            reader.onload = function(e) {
                $('#s_photo').attr('src', e.target.result);
                $("#s_photo").css("display", "block");
            }

            reader.readAsDataURL(input.files[0]); // Convert to base64 string
        }
    }
</script>
    
<script type="text/javascript">
        $(document).ready(function() {
        var selectedVideoURL = "{{ isset($detail->video) ? url($detail->video) : ''}}";
        if (selectedVideoURL) {
            $('#videoPreview source').attr('src', selectedVideoURL);
            $('#videoPreview')[0].load();
            $('#videoPreview').css('display', 'block');
        }
    });

    // Handle changes to the video input
    $("#p_video").change(function() {
        readURLvideo(this);
    });

    function readURLvideo(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            
            reader.onload = function(e) {
                $('#videoPreview source').attr('src', e.target.result);
                $('#videoPreview')[0].load();
                $('#videoPreview').css('display', 'block');
            }

            reader.readAsDataURL(input.files[0]); // Convert to base64 string
        }
    }
</script>