@extends('admin.main')
@section('content')
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
    <h1>
        Edit Store
        <!-- <small>Optional description</small> -->
    </h1>
    <ol class="breadcrumb">
        <li><a href="{{ url ('admin') }}"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active"> Edit Store</li>
    </ol>
    </section>

    <!-- Main content -->
    <section class="content container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#store_info" data-toggle="tab" aria-expanded="true">Store Informations</a></li>
                        <li><a href="#store_owners" data-toggle="tab" aria-expanded="false">Store Owner/s</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="store_info">
                            <form class="form-horizontal" id="frm_edit_store"  enctype="multipart/form-data">
                                <input type="hidden" class="form-control" value="{{ $teamstore_array[0]->Id }}" name="store_id" reqiured="required" />
                                <div id="edit_store_msg"></div>
                                <div class="row">
                                    <div class="col-lg-8">
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label"></label>
                                            <div class="col-sm-8">
                                                <button type="button" id="btn_delete_store" data-store-url="{{ $teamstore_array[0]->StoreUrl }}" data-store-id="{{ $teamstore_array[0]->Id }}" class="btn btn-danger pull-right"><i class="fa fa-trash"></i> Delete this Store</button>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label">Store Name</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" id="store_name" value="{{ $teamstore_array[0]->StoreName }}" name="store_name" placeholder="Store Name" reqiured="required" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label">Store URL</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" id="store_url" value="{{ $teamstore_array[0]->StoreUrl }}" name="store_url" placeholder="Store URL"  reqiured="required" />
                                                <input type="hidden" class="form-control" value="{{ $teamstore_array[0]->StoreUrl }}" name="orig_store_url" reqiured="required" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label">Store Currency</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" value="{{ $teamstore_array[0]->StoreCurrency }}" name="store_currency" placeholder="Store Currency"  reqiured="required" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">With Password</label>
                                            <div class="col-sm-8">
                                                <div class="checkbox">
                                                    <input type="checkbox" @if($teamstore_array[0]->Password != null) checked @endif id="with_password_opt" name="set_store_password" data-toggle="toggle" data-width="100px" data-on="<i class='fa fa-check-circle'></i> Yes" data-off="<i class='fa fa-ban'></i> No" data-size="small">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group store-password-field" style="display: @if($teamstore_array[0]->Password != null) block; @else none; @endif">
                                            <label  class="col-sm-4 control-label">Password</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" name="store_password" value="{{ $teamstore_array[0]->Password }}" placeholder="Store Password"  reqiured="required" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label">Store Logo</label>
                                            <div class="col-sm-8">
                                                <input type="file" data-use-id="img_store_logo" class="form-control upload_img" name="store_logo" placeholder="Store Logo"  reqiured="required" />
                                                <input type="hidden" class="form-control" value="{{ $teamstore_array[0]->StoreLogo }}" name="orig_store_logo" reqiured="required" />
                                                <small><i style="color: red;">Size: H:300px - W:300px</i></small>
                                            </div>
                                        </div>
                                        <div class="form-group" >
                                            <label  class="col-sm-4 control-label"></label>
                                            <div class="col-sm-8">
                                                <p>Store Logo Preview:</p>
                                                <div class="store-logo-holder">
                                                    <a href="{{ minio_url('uploads/images/teamstore/' . $teamstore_array[0]->ImageFolder . '/' . $teamstore_array[0]->StoreLogo) }}" class="img_store_logo_href"   data-toggle="lightbox">
                                                        <img class="img_store_logo_img"  id="img_store_logo" src="{{ minio_url('uploads/images/teamstore/' . $teamstore_array[0]->ImageFolder . '/' . $teamstore_array[0]->StoreLogo) }}" style="max-width: 100%; max-height: 100%; ">
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label">Store Banner</label>
                                            <div class="col-sm-8">
                                                <input type="file" class="form-control upload_img" data-use-id="img_store_banner" name="store_banner" placeholder="Store Banner"  reqiured="required" />
                                                <input type="hidden" class="form-control" value="{{ $teamstore_array[0]->StoreBanner }}" name="orig_store_banner" reqiured="required" />
                                                <small><i style="color: red;">Size: H:1140px - W:128px</i></small>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label"></label>
                                            <div class="col-sm-8">
                                                <p>Store Banner Preview:</p>
                                                <div class="store-banner-holder">
                                                    <a href="{{ minio_url('uploads/images/teamstore/' . $teamstore_array[0]->ImageFolder . '/' . $teamstore_array[0]->StoreBanner) }}" class="img_store_banner_href"   data-toggle="lightbox">
                                                        <img class="img_store_banner_img"  id="img_store_banner" src="{{ minio_url('uploads/images/teamstore/' . $teamstore_array[0]->ImageFolder . '/' . $teamstore_array[0]->StoreBanner) }}" style="max-width: 100%; max-height: 100%;">
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label">Store Status</label>
                                            <div class="col-sm-8">
                                                <select class="form-control" name="store_status">
                                                    <option @if($teamstore_array[0]->IsActive == "false") selected @endif>Private</option>
                                                    <option @if($teamstore_array[0]->IsActive == "true") selected @endif >Public</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">Hibernate</label>
                                            <div class="col-sm-8">
                                                <div class="checkbox">
                                                    <input type="checkbox" @if($teamstore_array[0]->IsHibernated == 1) checked @endif id="store_hibernate" name="store_hibernate" data-toggle="toggle" data-width="100px" data-on="<i class='fa fa-check-circle'></i> Yes" data-off="<i class='fa fa-ban'></i> No" data-size="small">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label  class="col-sm-4 control-label">&nbsp;</label>
                                            <div class="col-sm-8">
                                                <button type="submit" id="btn_update_store" class="btn btn-primary" style="width: 140px;">Save Changes</button>
                                                <a href="{{ url('admin/stores-list') }}" type="button" class="btn btn-default">Cancel</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                
                            </form>
                        </div>
                        <!-- end store_info tab-pane -->
                        <div class="tab-pane" id="store_owners">
                            <div class="well">
                                <button class="btn btn-primary" data-toggle="modal" data-target="#modal_add_existing_user" type="button">Add Existing User as Store Owner</button>
                                <button class="btn btn-primary" data-toggle="modal" data-target="#modal_create_new_user" type="button">Create New User as Store Owner</button>
                            </div>
                            <div class="table-responsive"> 
                                <table id="store_owners_table" class="table table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th>Fullname</th>
                                            <th>Username</th>
                                            <th>Email Address</th>
                                            <th>Created Date</th>
                                            <th>Last Update</th>
                                            <th class="text-center">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach($store_owners_array as $owner)
                                            <tr>
                                                <td>{{ $owner->name }}</td>
                                                <td>{{ $owner->username }}</td>
                                                <td>{{ $owner->email }}</td>
                                                <td>{{ date("F j, Y g:i a", strtotime($owner->created_at)) }}</td>
                                                <td>{{ date("F j, Y g:i a", strtotime($owner->updated_at)) }}</td>
                                                <td class="text-center">
                                                    <!-- <a href="#" class="btn btn-danger btn-xs">Reset Password</a> -->
                                                    <button type="button" data-id="{{ $owner->id }}" class="btn btn-danger btn-xs remove-store-access">Remove as Store Owner</button>
                                                </td>
                                            </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <!-- end store_owners tab-pane -->
                    </div>
                    <!-- /.tab-content -->
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>

<div class="modal fade" id="modal_add_existing_user" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<form id="frm_tag_user_as_store_owner" class="form-horizontal">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title" id="myModalLabel">Adding Existing User as Store Owner</h4>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-md-12">
                            <!-- <div id="add_publisher_msg"></div> -->
                            <div class="form-group">
                                <div class="col-sm-12">
                                <label  class="control-label">Search User</label>
                                    <input type="hidden" name="store_id" value="{{ $teamstore_array[0]->Id }}" />
                                    <input type="hidden" name="user_id" id="user_id" />                                    
                                    <!-- <textarea name="publisher" class="form-control capitalizeFirstLetter" required></textarea> -->
                                    <select name="user_name" class="form-control select2-select-user" data-error="#err_user_name"  style="width: 100%;">
                                        <option></option>
                                    </select>
                                    <span class="" id="err_user_name"></span>
                                </div>
                            </div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="submit" class="btn btn-primary">Submit</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
				</div>
			</form>
		</div>
	</div>
</div>

<div class="modal fade" id="modal_create_new_user" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<form id="frm_create_user_as_store_owner" class="form-horizontal">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title" id="myModalLabel">Creating New User as Store Owner</h4>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-md-12">
                            <div id="add_user_msg"></div>
                            <input type="hidden" name="store_id" value="{{ $teamstore_array[0]->Id }}" />
                            <div class="form-group">
                                <div class="col-sm-12">
                                    <label class="control-label">Fullname</label>
                                    <input type="text" class="form-control" name="name" value="{{ old('name') }}" placeholder="Fullname">
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-12">
                                    <label class="control-label">Username</label>
                                    <input type="text" class="form-control" name="username" value="{{ old('username') }}" placeholder="Username">
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-12">
                                    <label class="control-label">Email Address</label>
                                    <input type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email Address">
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-12">
                                    <label class="control-label">Password</label>
                                    <input type="password" class="form-control" name="password" id="password"  required placeholder="Password">
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-12">
                                    <label class="control-label">Confirm Password</label>
                                    <input type="password" class="form-control" name="password_confirmation" placeholder="Confirm Password" data-rule-equalTo="#password" required>
                                </div>
                            </div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="submit" class="btn btn-primary">Submit</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
				</div>
			</form>
		</div>
	</div>
</div>
@endsection