<?php 
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$admin_vendor_page_nonce = wp_create_nonce( 'admin_vendor_page_nonce' );

?>
	<div class="elex-multi-vendor-for-woocommerce-wrap elex-multi-vendor-for-woocommerce-wrap-admin overflow-hidden d-flex position-relative">

		<div class="elex-multi-vendor-for-woocommerce-main p-2 flex-1 me-4 d-flex flex-column">


			<!-- main content top link and search -->
			<img class="w-100 mb-2" src="<?php echo esc_url( ELEX_MULTI_VENDOR_MAIN_URL_PATH . 'images/top-banner.png' ); ?>" alt="">
			<div class="toast p-3 position-fixed top-0 start-50 translate-middle-x bg-white mt-3" id="elex_popup_vendor_reject_item_toast" style="min-width: 450px;">
					<div class="toast-header border-0 border-bottom p-0 pb-2">
						<strong class="mx-auto">
							<svg xmlns="http://www.w3.org/2000/svg" width="18" height="20" viewBox="0 0 20 22" class="me-2">
								<g id="Icon_feather-trash-2" data-name="Icon feather-trash-2" transform="translate(-3.5 -2)">
									<path id="Path_648" data-name="Path 648" d="M4.5,9h18" transform="translate(0 -2)" fill="none" stroke="#dc3545" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
									<path id="Path_649" data-name="Path 649" d="M21.5,7V21a2,2,0,0,1-2,2H9.5a2,2,0,0,1-2-2V7m3,0V5a2,2,0,0,1,2-2h4a2,2,0,0,1,2,2V7" transform="translate(-1 0)" fill="none" stroke="#dc3545" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
									<path id="Path_650" data-name="Path 650" d="M15,16.5v6" transform="translate(-3.5 -4.5)" fill="none" stroke="#dc3545" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
									<path id="Path_651" data-name="Path 651" d="M21,16.5v6" transform="translate(-5.5 -4.5)" fill="none" stroke="#dc3545" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
								</g>
								</svg>
								Rejection Alert</strong>
						<button type="button" class="btn-close" data-bs-dismiss="toast"></button>
					</div>
					<div class="toast-body p-0">
						<div class="fs-6 fw-semi-bold my-2">Are you sure, you want to reject vendor?</div>

						<label for="elex-multi-vendor-for-woocommerce-reject-vendor-input" class="fs-6 fw-semi-bold my-2">Reason(s) for Rejection:</label>
						<textarea type="textarea" class="form-control mb-3" id = "elex-multi-vendor-for-woocommerce-reject-vendor-input"></textarea>

						<div class="d-flex gap-3 justify-content-center ">
							<button class="btn px-4 btn-outline-secondary" data-bs-dismiss="toast">Cancel</button>
							<button class="btn px-4 btn-primary" id="elex-multi-vendor-for-woocommerce-reject-vendor-confirm-btn">
								Confirm
							</button>
						</div>
						</div>
					 
				</div>
			<div class="d-flex justify-content-between align-items-center mb-3">
				<div class="fs-5 mb-1 fw-semi-bold mb-0 ">Manage Vendors</div>
				<!-- new product button -->
				<button class="btn btn-primary elex-multi-vendor-for-woocommerce-add-vendor-btn ms-auto">
					<i class="fa-solid fa-plus"></i>
					Add New Vendor
				</button>
			</div>

			<div class="toast p-2 position-fixed top-0 start-50 translate-middle-x bg-white" id="elex_mv_vendor_buk_action_admin_toast" style="z-index: 1;" >
				<div class="toast-header border-0 ">
					<strong class="me-auto">
						<svg xmlns="http://www.w3.org/2000/svg" width="22.415" height="22.026" viewBox="0 0 22.415 22.026" class="me-2">
							<g id="Icon_feather-check-circle" data-name="Icon feather-check-circle" transform="translate(-1.998 -1.979)">
							<path id="Path_646" data-name="Path 646" d="M23,12.076V13a10,10,0,1,1-5.93-9.139" fill="none" stroke="#28a745" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
							<path id="Path_647" data-name="Path 647" d="M26.5,6l-10,10.009-3-3" transform="translate(-3.5 -1.003)" fill="none" stroke="#28a745" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
							</g>
						</svg>
						<span id="toast_message_mv_admin_bulk" >New item Added Successfully</span></strong>
					<button type="button" class="btn-close" data-bs-dismiss="toast"></button>
				</div>
			</div>
			
			<!-- main content top 2nd link section -->
			<div class="row justify-content-between align-items-start">
				<div class="col-lg-8 col-md-7  overflow-auto mb-2 elex-multi-vendor-for-woocommerce-product-filters">
					<div class="d-flex gap-2 flex-wrap p-md-0 px-2 py-4 elex-table-links-btn">
						<div class="form-group d-flex gap-2 h-100">
							<select name="" id="manage-vendor-bulk-action-select" class="form-select">
								<option value="">Bulk Actions</option>
								<option value="publish">Mark as Approved</option>
								<option value="reject">Mark as Rejected</option>
								<option value="private">Disable Vendor</option>
							</select>
							<button class="btn btn-primary px-4" id="manage-vendor-bulk-action-select-btn" >Apply</button>
						</div>
						<?php
						
						$filter_link_all = remove_query_arg( array( 'status', 'search', 'page_num','admin_vendor_page_nonce' ) );
						$filter_link_all = add_query_arg( 'admin_vendor_page_nonce', $admin_vendor_page_nonce, $filter_link_all );
						$is_all_filter_active = '';
						if ( empty( $status ) ) {
							$is_all_filter_active = 'active';
						}

						?>
						<a href="<?php echo esc_url( $filter_link_all ); ?>" class="btn border border-secondary bg-secondary bg-opacity-10 text-secondary text-nowrap <?php echo esc_attr( $is_all_filter_active ); ?>">
							All
						</a>

						<?php 
							$filter_link_main = remove_query_arg( array('page_num','admin_vendor_page_nonce') );
							$filter_link_main = add_query_arg( 'admin_vendor_page_nonce', $admin_vendor_page_nonce, $filter_link_main );
						?>

						<?php foreach ( $vendor_statuses as $vendor_status ) : ?>
						<?php
							$filter_link = add_query_arg( 'status', $vendor_status, $filter_link_main );
							$active_class = '';
							if ( ! empty( $status ) && $status === $vendor_status ) {
								$active_class = 'active';
							}
							$tag_string = $wp_post_statuses[ $vendor_status ]->label;
							if ( 'Private' === $tag_string ) {
								$tag_string = 'Disabled';
							}
						?>
						<a href="<?php echo esc_url( $filter_link ); ?>" class="btn border border-secondary bg-secondary bg-opacity-10 text-secondary text-nowrap <?php echo esc_attr($active_class); ?>">
							<?php echo esc_html( $tag_string ); ?>

							<?php if ( isset( $vendor_count_by_status[ $vendor_status ] ) && 0 !== $vendor_count_by_status[ $vendor_status ] ) : ?>
								<span>(<?php echo esc_html( $vendor_count_by_status[ $vendor_status ] ); ?>)</span>
							<?php endif; ?>
						</a>
						<?php endforeach; ?>
						<!-- <a href="#" class="text-decoration-underline btn fs-6 text-info" id="clear-filter-for-manage-product-btn" >clear filters</a> -->

					</div>
				</div>
				<div class="col-xl-3 col-lg-4 col-md-5  mb-3">
						<div class="input-group h-100  rounded-3 flex-nowrap ">
								<select type="text" name="vendor-select-for-search"  id="vendor-select-for-search" class="form-select select2-noborder" ></select>
								<?php
								if ( ! empty( $vendor_search ) ) {
									?>
								<button class="input-group-text bg-transparent border-0" id="vendor-select-for-search-cross"><svg xmlns="http://www.w3.org/2000/svg" id="Outline" viewBox="0 0 24 24" width="16" height="16" style="stroke-width:1;stroke:#000"><path d="M23.707.293h0a1,1,0,0,0-1.414,0L12,10.586,1.707.293a1,1,0,0,0-1.414,0h0a1,1,0,0,0,0,1.414L10.586,12,.293,22.293a1,1,0,0,0,0,1.414h0a1,1,0,0,0,1.414,0L12,13.414,22.293,23.707a1,1,0,0,0,1.414,0h0a1,1,0,0,0,0-1.414L13.414,12,23.707,1.707A1,1,0,0,0,23.707.293Z"/></svg></button>

								<?php
								}
								?>
								<input type="hidden" id="admin_vendor_page_nonce"  name="admin_vendor_page_nonce" value="<?php echo esc_attr( $admin_vendor_page_nonce ); ?>" />
								
								<button class="input-group-text border-0" id="search-vendor-btn" >
								<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" width="20" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
									<path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" />
								</svg>


								</button>
						</div>
				</div>
			</div>


			<!-- product list table -->
			<div class="table-responsive p-1 flex-fill">
				<table id="elex-multi-vendor-for-woocommerce-prod-table" class="table table-borderless align-middle text-dark ">
					<thead class="table-light rounded-2">
						<tr class="">
							<th class="manage-vendor-check"><input class=" vendor-all-checkbox" type="checkbox" value=""></th>
							<th scope="col" class="manage-vendor-details">Store Details</th>
							<th scope="col" class="manage-vendor-contact">Contact Details</th>
							<th scope="col" class="manage-vendor-product">No. Of Product(s)</th>
							<th scope="col" class="manage-vendor-status">Status</th>
							<th scope="col" class="manage-vendor-action">Actions</th>
						</tr>
					</thead>


					<tbody>
<?php 
foreach ( $vendor_stores as $value ) {
	?>

	<tr class="shadow-sm rounded-3" data-vendor-id="<?php echo esc_attr( $value->ID ); ?>">
							<td><input class=" vendor-individ-checkbox" type="checkbox" name="vendor-individ-checkbox[]" value="<?php echo esc_attr( $value->ID ); ?>" ></td>
							<td class="table-prod-details">
								<div class="d-flex gap-3 align-items-center ">

								<img src="
								<?php 

							 
								echo has_post_thumbnail( $value->ID ) ? esc_url( get_the_post_thumbnail_url( $value ) ) : esc_url( ELEX_MULTI_VENDOR_MAIN_URL_PATH . 'assets/images/default-store-icon.svg' ); 
								
								?>
								"
										alt="">
									<div class="text-start">
										<div class="fs-6 mb-1"><b> <?php echo esc_html( $value->post_title ); ?>  </b>
										<?php
										if ( 'publish' === $value->post_status && isset( $admin_params['elex_mv_store_slug'] ) && isset( $value->post_title ) ) {
											?>
												<a target="_blank" rel="noopener noreferrer" href="<?php echo esc_url( home_url( '/' . $admin_params['elex_mv_store_slug'] . '/' . $value->post_title ) ); ?>" class="btn btn-sm shadow-none text-info" data-bs-toggle="tooltip"
												data-bs-custom-class="tooltip-primary" data-bs-placement="bottom"
												title="Open Store page in a New Tab"><i
													class="fa-solid fa-arrow-up-right-from-square "></i></a>	
										<?php	
										}
										?>
											
										</div>
										
										<div class="fs-6 mb-1 text-secondary pe-none"><small>Dated: 
										<?php 
										$date_fomat = get_option( 'date_format' );
										echo esc_html( gmdate( $date_fomat , strtotime( $value->post_date ) ) ); 
										?>
										</small></div>

									</div>
								</div>
							</td>
							<td>
								<div class="fs-6 mb-1 fw-semi-bold"><a href="#"  class=" pe-none text-secondary text-decoration-none"> <?php echo esc_html( $vendors[ $value->post_author ]['display_name'] ); ?> </a></div>
								<small class="text-secondary"><?php echo esc_html( $vendors[ $value->post_author ]['user_email'] ); ?></small>
							</td>
							<td>
							<div class="fs-6 mb-1 fw-semi-bold text-info"><?php echo isset( $store_products_count[ $value->ID ] ) ? esc_html( $store_products_count[ $value->ID ] ) : 0 ; ?></div>
							</td>
							<td>
							<button class="btn pe-none btn-sm 
							<?php 
							if ( 'publish' === $value->post_status ) {
								echo esc_html( ' btn-success' );
							}
							if ( 'pending' === $value->post_status ) {
								echo esc_html( ' btn-info' );
							}
							if ( 'private' === $value->post_status ) {
								echo esc_html( ' btn-secondary' );
							}
							if ( 'reject' === $value->post_status ) {
								echo esc_html( ' btn-danger' );
							}$value->post_status 
							?>
				text-white px-4"> 
	<?php
	if ( 'Private' === $wp_post_statuses[ $value->post_status ]->label ) {
		echo esc_html( 'Disabled' ); 

	} else {
		echo esc_html( $wp_post_statuses[ $value->post_status ]->label );
	}
   
	?>
	</button>
	</td>
	<td>
	<?php if ( 'pending' !== $value->post_status && 'reject' !== $value->post_status ) : ?>
	<div class="d-flex gap-2">
	<?php if ( 'pending' !== $value->post_status ) : ?>

		<label class="elex-enable-disable-switch" >
		<input type="checkbox" class="elex-enable-disable-switch-val" 
		<?php 
			if ( 'publish' === $value->post_status ) {
	echo esc_attr( 'checked' ); } 
			?>
		data-vendor-id="<?php echo esc_attr( $value->ID ); ?>"  >
		<div class="switch round"></div>
		</label>
	<?php endif; ?>

	<div class="elex-multi-vendor-for-woocommerce-vendor-approved-group-btns">
	<div class="d-flex gap-2 align-items-center">

	<svg xmlns="http://www.w3.org/2000/svg" width="1.5" height="22"
	viewBox="0 0 2 25.587">
	<path id="carrier_seperator" data-name="carrier seperator"
	d="M2565.89-576v23.587" transform="translate(-2564.89 577)"
	fill="none" stroke="#707070" stroke-linecap="round"
	stroke-width="2" />
	</svg>


	
	
			</div>
			</div>
	<?php endif; ?>
	
	<?php if ( 'pending' === $value->post_status ) : ?>
			<div class="elex-multi-vendor-for-woocommerce-vendor-pending-group-btns">
				<div class="d-flex gap-2 align-items-center">
				<svg xmlns="http://www.w3.org/2000/svg" width="1.5" height="22"
				viewBox="0 0 2 25.587">
				<path id="carrier_seperator" data-name="carrier seperator"
				d="M2565.89-576v23.587" transform="translate(-2564.89 577)"
				fill="none" stroke="#707070" stroke-linecap="round"
				stroke-width="2" />
				</svg>

				<button
				class="btn btn-sm text-primary d-flex gap-2 align-items-center elex-vendor-approve-status approve" data-status="approve" data-vendor-id="<?php echo esc_attr( $value->ID ); ?>">
					<i class="fa-solid fa-check-double"></i>
					Approve</button>
					<svg xmlns="http://www.w3.org/2000/svg" width="1.5" height="22"
					viewBox="0 0 2 25.587">
					<path id="carrier_seperator" data-name="carrier seperator"
					d="M2565.89-576v23.587" transform="translate(-2564.89 577)"
					fill="none" stroke="#3F5980" stroke-linecap="round"
					stroke-width="2" />
					</svg>

					<button
					class="btn btn-sm text-primary d-flex gap-2 align-items-center elex-vendor-reject-status reject" data-status="reject" data-vendor-id="<?php echo esc_attr( $value->ID ); ?>">
						<svg xmlns="http://www.w3.org/2000/svg" width="9.333" height="9.333"
						viewBox="0 0 9.333 9.333">
						<path id="cancel_icon" data-name="cancel icon"
						d="M12.667,4.273l-.94-.94L8,7.06,4.273,3.333l-.94.94L7.06,8,3.333,11.727l.94.94L8,8.94l3.727,3.727.94-.94L8.94,8Z"
						transform="translate(-3.333 -3.333)" fill="#3f5980" />
						</svg>
						Reject</button>
						<svg xmlns="http://www.w3.org/2000/svg" width="1.5" height="22"
					viewBox="0 0 2 25.587">
					<path id="carrier_seperator" data-name="carrier seperator"
					d="M2565.89-576v23.587" transform="translate(-2564.89 577)"
					fill="none" stroke="#3F5980" stroke-linecap="round"
					stroke-width="2" />
					</svg>
						
	<?php endif; ?>

	<button
		class="btn btn-sm text-primary d-flex gap-2 align-items-center elex-multi-vendor-for-woocommerce-edit-vendor-btn" data-vendor-id="<?php echo esc_attr( $value->ID ); ?>" data-status="<?php echo esc_attr( $value->post_status ); ?>" >
			<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
			viewBox="0 0 18.638 18.695">
			<g id="Icon_feather-edit-3" data-name="Icon feather-edit-3"
			transform="translate(-3.486 -3.183)">
			<path id="Path_29" data-name="Path 29" d="M17.8,30.363H26.12"
			transform="translate(-4.996 -9.486)" fill="none"
			stroke="#3f5980" stroke-linecap="round"
			stroke-linejoin="round" stroke-width="2" />
			<path id="Path_30" data-name="Path 30"
			d="M16.964,4.775a1.92,1.92,0,0,1,2.773,0,2.308,2.308,0,0,1,0,3.067L7.952,19.344,4.486,20.878l.693-3.834Z"
			transform="translate(0 0)" fill="none" stroke="#3f5980"
			stroke-linecap="round" stroke-linejoin="round"
			stroke-width="2" />
			</g>
			</svg>
			</button>
					</div>
			</div>


					</td>


					</tr>

<?php
}
?>

					</tbody>
				</table>
			</div>

			<!-- page navigatio -->
			<div class="d-flex justify-content-center gap-3">
			<nav aria-label="Page navigation example">
	<ul class="pagination gap-4 mt-3">
	<li class="page-item"><a class="page-link btn btn-sm border-0
		<?php
		$filter_link = remove_query_arg( array( 'admin_vendor_page_nonce' ) );
		if ( 1 === $page_number ) { ?>
			disabled 
		<?php } ?>"  
			href=" 
		<?php 
		echo esc_url(
			add_query_arg(
				array(
					'page_num' => $prev,
					'admin_vendor_page_nonce' => $admin_vendor_page_nonce,
				),
				$filter_link
			) 
		); 
		?>
		"><i class="fa-solid fa-chevron-left"></i> Previous</a>
	</li>
	<li class="page-item"><a class="page-link btn btn-sm border-0

		<?php
	

		if ( (string) $total_pages === (string) $page_number ) { 
			?>
				disabled 
		<?php } ?>"  
		href="
		<?php 
				$next_url = add_query_arg(
					array(
						'page_num' => $next,
						'admin_vendor_page_nonce' => $admin_vendor_page_nonce,
					),
					$filter_link
				);
				echo esc_url( $next_url ); 
				?>
				">Next <i class="fa-solid fa-chevron-right"></i> </a>
	</li>
	</ul>  
</nav>
			</div>
		</div>


		<!-- =========================popup=================== -->

	<?php require ELEX_MULTI_VENDOR_PLUGIN_PATH . 'templates/manage-vendors-dashboard/add-vendors-popup.php'; ?>
		
	<?php require ELEX_MULTI_VENDOR_PLUGIN_PATH . 'templates/manage-vendors-dashboard/edit-vendors-popup.php'; ?>

	 
	</div>
