<?php
	session_start();
	if($_SESSION['unohs'] == null){
		header("location:index.php?msg=unauthorized");
	}
?>
<?php
	include ("conn.php");
	
	if($id=encryptor('decrypt', $_GET['id'])){	
		/* ══════════════════════════════════════════════════════════
		   FIX — hintegedukolli.khateshonu আসলে দুই ধরনের Withdraw
		   Method-এর যেকোনো একটাকে Reference করতে পারে:
		   (1) Bank Transfer → khate.shonu
		   (2) Mobile Wallet (bKash/Nagad ইত্যাদি) → bankcard.id
		   আগে শুধু khate-এর সাথে Join করা হতো, তাই Wallet দিয়ে করা
		   Withdraw-এ সব "N/A" দেখাতো। এখন দুটোর সাথেই LEFT JOIN করে,
		   যেটাতে Match পাওয়া যায় সেটাই দেখানো হবে।
		   ══════════════════════════════════════════════════════════ */
		$Query=mysqli_query($conn,"select shonu_subjects.mobile,shonu_subjects.email,shonu_subjects.owncode,
		khate.phalanubhavi,khate.kod,khate.khatehesaru,khate.khatesankhye,
		bankcard.type as wallet_type, bankcard.name as wallet_name, bankcard.account as wallet_account,
		`hintegedukolli`.`shonu`,`hintegedukolli`.`balakedara`,`hintegedukolli`.`dharavahi`,`hintegedukolli`.`motta`,`hintegedukolli`.`khateshonu`,`hintegedukolli`.`madari`,`hintegedukolli`.`sthiti`,`hintegedukolli`.`dinankavannuracisi` from `hintegedukolli`
		LEFT JOIN shonu_subjects ON shonu_subjects.id=`hintegedukolli`.`balakedara`
		LEFT JOIN khate ON khate.shonu=`hintegedukolli`.`khateshonu`
		LEFT JOIN bankcard ON bankcard.id=`hintegedukolli`.`khateshonu` AND khate.shonu IS NULL
		where `hintegedukolli`.`shonu`='".$id."'");
		$Result=mysqli_fetch_array($Query);
	}
	/* এখন recordNotFound শুধু তখনই true হবে যদি hintegedukolli-তেই
	   এই ID-র কোনো Withdraw Request না থাকে (একদম Invalid Link)। */
	$recordNotFound = empty($Result);
	$isWalletWithdraw = !$recordNotFound && empty($Result['khatehesaru']) && !empty($Result['wallet_account']);
	/* Wallet Type Code → Name Mapping (GetBankList.php-এ পাওয়া, madari=4 হলে) */
	$walletTypeNames = [175 => 'BKASH', 176 => 'ROCKET', 177 => 'UPAY', 178 => 'NAGAD'];
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Dashboard</title>
  <link rel="stylesheet" href="vendors/mdi/css/materialdesignicons.min.css">
  <link rel="stylesheet" href="vendors/feather/feather.css">
  <link rel="stylesheet" href="vendors/base/vendor.bundle.base.css">
  <link rel="stylesheet" href="vendors/flag-icon-css/css/flag-icon.min.css"/>
  <link rel="stylesheet" href="vendors/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="vendors/jquery-bar-rating/fontawesome-stars-o.css">
  <link rel="stylesheet" href="vendors/jquery-bar-rating/fontawesome-stars.css">
  <link rel="stylesheet" href="css/style.css">
  <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
  <link rel="stylesheet" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css">
  <link rel="stylesheet" href="https://cdn.datatables.net/fixedheader/3.2.3/css/fixedHeader.dataTables.min.css">
  <link rel="shortcut icon" href="images/favicon.png" />
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500;600&display=swap">
  <style>
	.cool-input {
        border: 2px solid #007bff;
        border-radius: 0.25rem;
        padding: 0.5rem 1rem;
        font-size: 1rem;
        transition: all 0.3s ease;
    }
    .cool-input:focus {
        border-color: #0056b3;
        box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    }
    .cool-input::placeholder {
        color: #6c757d;
        opacity: 1;
    }
	.cool-button {
        padding: 0.5rem 1rem;
        font-size: 1rem;
        border-radius: 0.25rem;
        transition: all 0.3s ease;
    }
    .cool-button:hover {
        background-color: #0056b3;
        color: #fff;
    }
    .cool-button.btn-secondary:hover {
        background-color: #343a40;
        color: #fff;
    }
	#copied{
		visibility: hidden;
		z-index: 1;
		position: fixed;
		bottom: 50%;
		background-color: #333;
		color: #fff;
		border-radius: 6px;
		padding: 16px;
		max-width: 250px;
		font-size: 17px;
	}	   
	#copied.show {
		visibility: visible;
		-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
		animation: fadein 0.5s, fadeout 0.5s 2.5s;
	}

	/* ══════════════════════════════════════════════════════════
	   PREMIUM WITHDRAW CARD — Dark Navy / Gold Fintech Theme
	   ══════════════════════════════════════════════════════════ */
	:root{
		--wd-bg-deep:#100B22;
		--wd-panel:#1B1633;
		--wd-panel-2:#221A44;
		--wd-border:rgba(245,197,66,0.22);
		--wd-gold:#F5C542;
		--wd-gold-soft:#E9C77A;
		--wd-text:#EFEBFB;
		--wd-text-muted:#9691B8;
		--wd-emerald:#22C58B;
		--wd-emerald-deep:#159A6B;
		--wd-coral:#F75676;
		--wd-coral-deep:#D63A58;
	}
	.wd-wrap{
		font-family:'Inter',sans-serif;
		max-width:640px;
		margin:24px auto 40px;
	}
	.wd-card{
		background:linear-gradient(165deg, var(--wd-panel) 0%, var(--wd-bg-deep) 100%);
		border:1px solid var(--wd-border);
		border-radius:18px;
		padding:0;
		overflow:hidden;
		box-shadow:0 20px 50px -20px rgba(0,0,0,0.6), 0 0 0 1px rgba(245,197,66,0.05) inset;
	}
	.wd-card-head{
		padding:26px 28px 20px;
		border-bottom:1px solid rgba(245,197,66,0.14);
		display:flex;
		align-items:center;
		justify-content:space-between;
		gap:12px;
	}
	.wd-eyebrow{
		font-family:'Inter',sans-serif;
		font-size:11px;
		letter-spacing:.14em;
		text-transform:uppercase;
		color:var(--wd-text-muted);
		margin:0 0 4px;
	}
	.wd-title{
		font-family:'Sora',sans-serif;
		font-weight:700;
		font-size:22px;
		color:var(--wd-text);
		margin:0;
		letter-spacing:-0.01em;
	}
	.wd-badge{
		font-family:'Inter',sans-serif;
		font-weight:600;
		font-size:12px;
		letter-spacing:.04em;
		padding:7px 14px;
		border-radius:999px;
		white-space:nowrap;
	}
	.wd-badge-pending{ background:rgba(245,197,66,0.14); color:var(--wd-gold); border:1px solid rgba(245,197,66,0.35); }
	.wd-badge-closed{ background:rgba(150,145,184,0.14); color:var(--wd-text-muted); border:1px solid rgba(150,145,184,0.3); }

	.wd-body{ padding:6px 28px 8px; }
	.wd-row{
		display:flex;
		align-items:baseline;
		justify-content:space-between;
		gap:16px;
		padding:15px 0;
		border-bottom:1px dashed rgba(150,145,184,0.18);
	}
	.wd-row:last-child{ border-bottom:none; }
	.wd-label{
		font-family:'Inter',sans-serif;
		font-size:13px;
		color:var(--wd-text-muted);
		white-space:nowrap;
	}
	.wd-value{
		font-family:'Inter',sans-serif;
		font-size:15px;
		font-weight:600;
		color:var(--wd-text);
		text-align:right;
	}
	.wd-value.mono{
		font-family:'JetBrains Mono',monospace;
		font-size:14px;
		letter-spacing:0.01em;
	}
	.wd-value.amount{
		font-family:'Sora',sans-serif;
		font-size:22px;
		font-weight:700;
		color:var(--wd-gold);
	}
	.wd-value.muted{ color:var(--wd-text-muted); font-weight:500; }
	.wd-copy{
		background:none;
		border:none;
		color:var(--wd-text-muted);
		cursor:pointer;
		margin-left:8px;
		font-size:13px;
		vertical-align:middle;
		transition:color .15s ease;
	}
	.wd-copy:hover{ color:var(--wd-gold); }

	.wd-section-label{
		font-family:'Inter',sans-serif;
		font-size:11px;
		letter-spacing:.12em;
		text-transform:uppercase;
		color:var(--wd-gold-soft);
		margin:22px 0 2px;
	}

	.wd-actions{
		display:flex;
		gap:12px;
		padding:22px 28px 28px;
	}
	.wd-btn{
		flex:1;
		font-family:'Inter',sans-serif;
		font-weight:600;
		font-size:15px;
		padding:14px 0;
		border-radius:12px;
		border:none;
		text-align:center;
		cursor:pointer;
		display:flex;
		align-items:center;
		justify-content:center;
		gap:8px;
		transition:transform .12s ease, box-shadow .12s ease;
		text-decoration:none;
	}
	.wd-btn:hover{ transform:translateY(-2px); text-decoration:none; }
	.wd-btn-agree{
		background:linear-gradient(180deg, var(--wd-emerald) 0%, var(--wd-emerald-deep) 100%);
		color:#06251A;
		box-shadow:0 10px 24px -10px rgba(34,197,139,0.55);
	}
	.wd-btn-reject{
		background:linear-gradient(180deg, var(--wd-coral) 0%, var(--wd-coral-deep) 100%);
		color:#2B0510;
		box-shadow:0 10px 24px -10px rgba(247,86,118,0.5);
	}
	.wd-empty{
		padding:36px 28px 30px;
		text-align:center;
	}
	.wd-empty-icon{ font-size:34px; margin-bottom:10px; }
	.wd-empty-title{
		font-family:'Sora',sans-serif;
		font-weight:700;
		color:var(--wd-text);
		font-size:17px;
		margin:0 0 8px;
	}
	.wd-empty-text{
		font-family:'Inter',sans-serif;
		color:var(--wd-text-muted);
		font-size:13.5px;
		line-height:1.6;
		margin:0 0 20px;
	}
	.wd-warn-strip{
		margin:0 28px 18px;
		padding:12px 16px;
		border-radius:10px;
		background:rgba(245,197,66,0.1);
		border:1px solid rgba(245,197,66,0.3);
		color:var(--wd-gold-soft);
		font-family:'Inter',sans-serif;
		font-size:13px;
		line-height:1.5;
	}
	@media (max-width:480px){
		.wd-wrap{ margin:12px 8px 28px; }
		.wd-card-head{ flex-direction:column; align-items:flex-start; }
	}
  </style>
</head>
<body>
  <div class="container-scroller">
    <nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
      <div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
        <a class="navbar-brand brand-logo" href="dashboard.php"><img src="images/logo.png" alt="logo"/></a>
        <a class="navbar-brand brand-logo-mini" href="dashboard.php"><img src="images/logo-mini.png" alt="logo"/></a>
      </div>
      <div class="navbar-menu-wrapper d-flex align-items-center justify-content-end">
        <button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
          <span class="icon-menu"></span>
        </button>       
        <ul class="navbar-nav navbar-nav-right">           
          <li class="nav-item dropdown d-flex mr-4 ">
            <a class="nav-link count-indicator dropdown-toggle d-flex align-items-center justify-content-center" id="notificationDropdown" href="#" data-toggle="dropdown">
              <i class="icon-cog"></i>
            </a>
            <div class="dropdown-menu dropdown-menu-right navbar-dropdown preview-list" aria-labelledby="notificationDropdown">
              <p class="mb-0 font-weight-normal float-left dropdown-header">Settings</p>              
              <a class="dropdown-item preview-item" href="logout.php">
                  <i class="icon-inbox"></i> Logout
              </a>
            </div>
          </li>
        </ul>
        <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
          <span class="icon-menu"></span>
        </button>
      </div>
    </nav>
    <div class="container-fluid page-body-wrapper">
      <nav class="sidebar sidebar-offcanvas" id="sidebar">
        <div class="user-profile">
          <div class="user-image">
            <img src="images/faces/face28.png">
          </div>
          <div class="user-name">
              bigdelhi
          </div>
          <div class="user-designation">
              Admin
          </div>
        </div>
        <?php include 'compass.php';?>
      </nav>
      <div class="main-panel">
        <div class="content-wrapper">
          <div class="row">
            <div class="col-sm-12 mb-4 mb-xl-0">
              <h4 class="font-weight-bold text-dark">Withdraw Accept/Reject</h4>
            </div>
          </div> 		  		  		  			
		  <div class="row">
            <div class="col-sm-12">
				<div class="wd-wrap">
				  <div class="wd-card">
					<?php if ($recordNotFound) { ?>
						<div class="wd-empty">
							<div class="wd-empty-icon">🔍</div>
							<p class="wd-empty-title">Request খুঁজে পাওয়া যায়নি</p>
							<p class="wd-empty-text">এই Link-এর Withdraw Request-ই খুঁজে পাওয়া যায়নি —<br>সম্ভবত Invalid বা পুরনো একটা Link। Withdraw List-এ ফিরে যান।</p>
						</div>
					<?php } else { ?>
						<div class="wd-card-head">
							<div>
								<p class="wd-eyebrow">Withdraw Request</p>
								<h3 class="wd-title">#<?php echo $Result['shonu']; ?></h3>
							</div>
							<?php if ($Result['sthiti'] == 0) { ?>
								<span class="wd-badge wd-badge-pending">● Pending</span>
							<?php } else { ?>
								<span class="wd-badge wd-badge-closed"><?php echo $Result['sthiti'] == 1 ? '✓ Completed' : '✕ Rejected'; ?></span>
							<?php } ?>
						</div>

						<div class="wd-body">
							<div class="wd-row">
								<span class="wd-label">User ID</span>
								<span class="wd-value mono">#<?php echo $Result['balakedara'];?></span>
							</div>
							<div class="wd-row">
								<span class="wd-label">Mobile</span>
								<span class="wd-value mono"><?php echo $Result['mobile'] ?: 'N/A'; ?></span>
							</div>
							<div class="wd-row">
								<span class="wd-label">Transaction ID</span>
								<span class="wd-value mono"><?php echo $Result['dharavahi'] ?: 'N/A'; ?><?php if($Result['dharavahi']){ ?><button class="wd-copy" onclick="wdCopy('<?php echo $Result['dharavahi'];?>')" title="Copy">⧉</button><?php } ?></span>
							</div>
							<div class="wd-row">
								<span class="wd-label">Date</span>
								<span class="wd-value muted"><?php echo date('d M Y',strtotime($Result['dinankavannuracisi']));?></span>
							</div>
							<div class="wd-row">
								<span class="wd-label">Amount</span>
								<span class="wd-value amount">৳<?php echo number_format($Result['motta'],2);?></span>
							</div>
						</div>

						<?php if ($isWalletWithdraw) { ?>
						<p class="wd-section-label" style="padding-left:28px;">Mobile Wallet</p>
						<div class="wd-body" style="padding-top:0;">
							<div class="wd-row">
								<span class="wd-label">Method</span>
								<span class="wd-value"><?php echo $walletTypeNames[$Result['wallet_type']] ?? ('Type Code: '.$Result['wallet_type']); ?></span>
							</div>
							<div class="wd-row">
								<span class="wd-label">Account Name</span>
								<span class="wd-value"><?php echo $Result['wallet_name'] ?: 'N/A'; ?></span>
							</div>
							<div class="wd-row">
								<span class="wd-label">Wallet Number</span>
								<span class="wd-value mono"><?php echo $Result['wallet_account'] ?: 'N/A'; ?><?php if($Result['wallet_account']){ ?><button class="wd-copy" onclick="wdCopy('<?php echo $Result['wallet_account'];?>')" title="Copy">⧉</button><?php } ?></span>
							</div>
						</div>
						<?php } else { ?>
						<p class="wd-section-label" style="padding-left:28px;">Bank Details</p>
						<div class="wd-body" style="padding-top:0;">
							<div class="wd-row">
								<span class="wd-label">Bank Name</span>
								<span class="wd-value <?php echo $Result['khatehesaru'] ? '' : 'muted'; ?>"><?php echo $Result['khatehesaru'] ?: 'N/A — Bank record not found'; ?></span>
							</div>
							<div class="wd-row">
								<span class="wd-label">IFSC Code</span>
								<span class="wd-value mono <?php echo $Result['kod'] ? '' : 'muted'; ?>"><?php echo $Result['kod'] ?: 'N/A'; ?></span>
							</div>
							<div class="wd-row">
								<span class="wd-label">Account Number</span>
								<span class="wd-value mono <?php echo $Result['khatesankhye'] ? '' : 'muted'; ?>"><?php echo $Result['khatesankhye'] ?: 'N/A'; ?><?php if($Result['khatesankhye']){ ?><button class="wd-copy" onclick="wdCopy('<?php echo $Result['khatesankhye'];?>')" title="Copy">⧉</button><?php } ?></span>
							</div>
						</div>
						<?php } ?>

						<?php if (!$isWalletWithdraw && empty($Result['khatehesaru'])) { ?>
						<div class="wd-warn-strip">⚠️ Bank Account Record খুঁজে পাওয়া যায়নি। Accept করার আগে User-এর সাথে Details Verify করে নিন।</div>
						<?php } ?>

						<?php if($Result['sthiti'] == 0) { ?>
						<div class="wd-actions">
							<a href="javascript:void(0);" class="wd-btn wd-btn-agree" onClick="acceptrejectconfirm(<?php echo $Result['shonu'];?>,'accept');">✓ Agree</a>
							<a href="javascript:void(0);" class="wd-btn wd-btn-reject" onClick="acceptrejectconfirm(<?php echo $Result['shonu'];?>,'reject');">✕ Reject</a>
						</div>
						<?php } ?>
					<?php } ?>
				  </div>
				</div>
            </div>
          </div>		  
		</div>
		<div id="copied">Copied!</div>
		<script>
		function wdCopy(text){
			navigator.clipboard.writeText(text).then(function(){
				var x = document.getElementById("copied");
				x.className = "show";
				setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2500);
			});
		}
		</script>
		<footer class="footer">
			<div class="d-sm-flex justify-content-center justify-content-sm-between">
				<span class="text-muted d-block text-center text-sm-left d-sm-inline-block">Copyright © cv111.site 2024</span>
			</div>
		</footer>
      </div>     
    </div>
  </div>
	<div id="confirm" class="modal fade" role="dialog">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content" style="padding:8px;">
            <div class="modal-body text-center">
                Are you sure you want to <span id="typetext"></span>?
            </div>
            <input type="hidden" id="id" name="id" value="">
            <div class="form-group" id="remarkContainer">
                <label for="remark">Enter Remark:</label>
                <input type="text" id="remark" name="remark" class="form-control" placeholder="Enter your remark here">
            </div>

            <input type="hidden" id="type" name="type" value="">
            <div class="text-center">
                <a type="button" class="btn btn-sm btn-success text-light" onClick="acceptreject();">&nbsp;YES&nbsp;</a>&nbsp;
                <a type="button" class="btn btn-sm btn-danger text-light" data-dismiss="modal">&nbsp;NO&nbsp;</a>
            </div> 
        </div>
    </div>
</div>
  <script src="vendors/base/vendor.bundle.base.js"></script>
  <script src="js/off-canvas.js"></script>
  <script src="js/hoverable-collapse.js"></script>
  <script src="js/template.js"></script>
  <script src="vendors/chart.js/Chart.min.js"></script>
  <script src="vendors/jquery-bar-rating/jquery.barrating.min.js"></script>
  <script src="js/dashboard.js"></script>
  <script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
  <script>
    function acceptrejectconfirm(Id, type) {
        $('#confirm').modal({backdrop: 'static', keyboard: false});
        $('#confirm').modal('show');
        $('#id').val(Id);
        $('#type').val(type);
        document.getElementById('typetext').innerHTML = type;

        
    }

    function acceptreject() {
        var Id = $('#id').val();
        var Type = $('#type').val();

        $.ajax({
            type: "Post",
            data: "id=" + Id + "&type=" + Type + "&remark=" + $("#remark").val(),
            url: "manage_withdrawAction.php",
            success: function (html) {
                if (html == 1) {
                    window.location = 'withdraw_accept_list.php';
                } else {
                    window.location = 'withdraw_reject_list.php';
                }                
                return false;
            },
            error: function (e) {
            }
        });
    }
</script>
</body>

</html>