<?php
/* Edit Affiliates Page */

if ( ! defined( 'ABSPATH' ) ) {
	exit ; // Exit if accessed directly.
}
$ReferralIDs = ( array ) get_post_meta( $payout_id , 'referral_id' , true ) ;
$ReferralIDs = reset( $ReferralIDs ) ;
$UserData    = get_user_by( 'id' , $payout_obj->generate_by ) ;
$UserName    = is_object( $UserData ) ? $UserData->user_login : __( 'Automatic' , FS_AFFILIATES_LOCALE ) ;
?>
<div class="<?php echo $this->plugin_slug ; ?>_affiliates_edit">
	<h2><?php _e( 'Payout #' . $payout_id , FS_AFFILIATES_LOCALE ) ; ?></h2>
	<table class="form-table">
		<tbody>
			<tr>
				<th scope='row'>
					<label><?php _e( 'Affiliate Name' , FS_AFFILIATES_LOCALE ) ; ?></label>
				</th>
				<td>
					<label><?php echo $payout_obj->affiliate ; ?></label>
				</td>
			</tr>
			<tr>
				<th scope='row'>
					<label><?php _e( 'Commission' , FS_AFFILIATES_LOCALE ) ; ?></label>
				</th>
				<td>
					<label><?php echo fs_affiliates_price( $payout_obj->paid_amount ) ; ?></label>
				</td>
			</tr>
			<tr>
				<th scope='row'>
					<label><?php _e( 'Payout Generated By' , FS_AFFILIATES_LOCALE ) ; ?></label>
				</th>
				<td>
					<label><?php echo $UserName ; ?></label>
				</td>
			</tr>
			<tr>
				<th scope='row'>
					<label><?php _e( 'Status' , FS_AFFILIATES_LOCALE ) ; ?></label>
				</th>
				<td>
					<label><?php _e( 'Paid' , FS_AFFILIATES_LOCALE ) ; ?></label>
				</td>
			</tr>
			<tr>
				<th scope='row'>
					<label><?php _e( 'Payout Mode' , FS_AFFILIATES_LOCALE ) ; ?></label>
				</th>
				<td>
					<label><?php echo fs_affiliates_display_payment_method($payout_obj->payment_mode) ; ?></label>
				</td>
			</tr>
			<tr>
				<th scope='row'>
					<label><?php _e( 'Payout Date' , FS_AFFILIATES_LOCALE ) ; ?></label>
				</th>
				<td>
					<label><?php echo fs_affiliates_local_datetime( $payout_obj->date ) ; ?></label>
				</td>
			</tr>
		</tbody>
	</table>
	<h2><?php _e( 'Referrals' , FS_AFFILIATES_LOCALE ) ; ?></h2>
	<table class="form-table">
		<th><?php _e( 'Reference' , FS_AFFILIATES_LOCALE ) ; ?></th>
		<th><?php _e( 'Commission' , FS_AFFILIATES_LOCALE ) ; ?></th>
		<th><?php _e( 'Description' , FS_AFFILIATES_LOCALE ) ; ?></th>
		<th><?php _e( 'Type' , FS_AFFILIATES_LOCALE ) ; ?></th>
		<th><?php _e( 'Date' , FS_AFFILIATES_LOCALE ) ; ?></th>
		<tbody>
			<?php
			if ( ! fs_affiliates_check_is_array( $ReferralIDs ) ) {
				return ;
			}

			foreach ( $ReferralIDs as $Id ) {
				$ReferralObj = new FS_Affiliates_Referrals( $Id ) ;
				if ( ! is_object( $ReferralObj ) ) {
					continue ;
				}
				?>
				<tr>
					<td><?php echo '#' . $Id ; ?></td>
					<td><?php echo fs_affiliates_price( $ReferralObj->amount ) ; ?></td>
					<td><?php echo $ReferralObj->description ; ?></td>
					<td><?php echo ucfirst( $ReferralObj->type ) ; ?></td>
					<td><?php echo fs_affiliates_local_datetime( $ReferralObj->date ) ; ?></td>
				</tr>
			<?php } ?>
		</tbody>
	</table>
</div>
