@extends('layouts.adminapp')
@section('content')

{{-- Product Edit--}}

<form method="POST" action="{{route('Product.update',$Product->id)}}" enctype="multipart/form-data">
    @csrf
    @method('patch')
    <div class="card">
        <div class="card-header">        
            <div class="d-flex align-items-center">
                <div class="p-2  flex-fill bd-highlight">
                    <h4>Edit Product</h4>
                </div>            
            </div>  
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-sm-6 form-group">
                    <label for="txtName">Product Name</label>
                    <input type="text" class="form-control @error('title') is-invalid @enderror" name="title" id="txtName" value="{{$Product->title}}" required/>
                    @error('title')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
                {{--<div class="col-sm-6 form-group">
                    <label for="txtName">Amount</label>
                    <input type="text" class="form-control" name="amount" id="numAmount" value="{{$Product->amount}}"/>
                </div>--}}
                <div class="col-sm-3">
                    @if(isset($Product->image))
                    <img src="{{asset('storage/images/products/'.$Product->image)}}" alt="avatar" width="100px" id="imgImage"/>
                    @else
                    <img src="{{asset('images/imgicon.png')}}" alt="avatar" width="100px" id="imgImage"/>
                    @endif 
                </div>
                <div class="col-sm-3 form-group">
                    <label for="fileIcon">Choose File</label>
                    <input type="file" class="form-control-file" name="image" id="fileIcon" onchange="
                    var input=this;
		                if (input.files && input.files[0]) {
                        var reader = new FileReader();
                        var size=(Math.round(input.files[0].size/1024));
                        if(size>1024)
                            {
                            alert('Please Upload file lesthan 1MB\nControl load time');
                            input.value='';
                            }
                        else{
                            reader.onload = function (e) {
                            $('#imgImage').attr('src', e.target.result); 
                            }
                            reader.readAsDataURL(input.files[0]);
                            }
				    }">
                </div>
                <div class="col-sm-6 form-group">
                    <label for="txtName">Narration</label>
                    <input type="text" class="form-control" name="narration" id="txtNarration" value="{{$Product->narration}}"/>
                </div>
            </div>            
        </div>
        <div class="card-footer">
            <div class="d-flex  justify-content-start p-2" style="width:50%;float:left;">
                <a class="btn btn-primary" href="{{ route('Product.index') }}"><i class="fas fa-arrow-left"></i> Back</a>
            </div>
            <div class="d-flex  justify-content-end p-2">
                <button type="reset" class="btn btn-secondary mr-2" name="btnSave">Clear</button>
                <button type="submit" class="btn btn-primary" name="btnSave">Save</button>
            </div>
        </div>
    </div>
</form>




    {{-- <h1 class="text-2xl">Enter your next TODO</h1>
        <form method="post" action="{{route('Company.store')}}">
            @csrf
            <input type="text" name="title" class="py-2 px-2 border rounded"/>
            <input type="submit" value="Save Todo" class="p-2 rounded"/>
        </form>
        <x-flash/>
        <a href="{{route('Company.index')}}" class="btn btn-primary">Back</a> --}}
@endsection