<?php
	$path="../../";
	include("../../map.php");
	include("../../secure.php");
	include("../../scripts.php");
?>
<?php if($_GET["islem"]=="calc"){ ?>
<title>Hesap Makinesi</title>
<link href="https://www.jqueryscript.net/css/jquerysctipttop.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<!-- JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.17.0/math.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Default Stylesheet -->
<link rel="stylesheet" href="css/style.css">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
<div class="container" style="margin-top:0px;">
	<label class="switch">
		<input type="checkbox">
		<span class="slider"></span>
	</label>
	<form>
		<input readonly id="display1" type="text" class="form-control-lg text-right">
		<input readonly id="display2" type="text" class="form-control-lg text-right">
	</form>
	
	<div class="d-flex justify-content-between button-row">
		<button id="left-parenthesis" type="button" class="operator-group">&#40;</button>
		<button id="right-parenthesis" type="button" class="operator-group">&#41;</button>
		<button id="square-root" type="button" class="operator-group">&#8730;</button>
		<button id="square" type="button" class="operator-group">&#120;&#178;</button>
	</div>
  
	<div class="d-flex justify-content-between button-row">
		<button id="clear" type="button">&#67;</button>
		<button id="backspace" type="button">&#9003;</button>
		<button id="ans" type="button" class="operand-group">&#65;&#110;&#115;</button>
		<button id="divide" type="button" class="operator-group">&#247;</button>
	</div>
	
	<div class="d-flex justify-content-between button-row">
		<button id="seven" type="button" class="operand-group">&#55;</button>
		<button id="eight" type="button" class="operand-group">&#56;</button>
		<button id="nine" type="button" class="operand-group">&#57;</button>
		<button id="multiply" type="button" class="operator-group">&#215;</button>
	</div>
	
	<div class="d-flex justify-content-between button-row">
		<button id="four" type="button" class="operand-group">&#52;</button>
		<button id="five" type="button" class="operand-group">&#53;</button> 
		<button id="six" type="button" class="operand-group">&#54;</button> 
		<button id="subtract" type="button" class="operator-group">&#8722;</button>
	</div>
	
	<div class="d-flex justify-content-between button-row">
		<button id="one" type="button" class="operand-group">&#49;</button> 
		<button id="two" type="button" class="operand-group">&#50;</button>
		<button id="three" type="button" class="operand-group">&#51;</button>
		<button id="add" type="button" class="operator-group">&#43;</button>
	</div>
	<div class="d-flex justify-content-between button-row">
		<button id="percentage" type="button" class="operand-group">&#37;</button>
		<button id="zero" type="button" class="operand-group">&#48;</button>
		<button id="decimal" type="button" class="operand-group">&#46;</button>
		<button id="equal" type="button">&#61;</button>
	</div>
</div>
<script src="js/main.js" type="text/javascript"></script>
<?php }elseif($_GET["islem"]=="exc"){?>
<title>Döviz Çevirici</title>
<div class="v3-col-md-12">
  <div class="input-group" style="margin-top:15px">
    <input type="text" id="prc1" class="form-control" placeholder="Tutar" value="1" style="border:1px solid #ccc!important;padding:23px;">
    <span class="input-group-addon" style="width:25%;">
      <select class="form-control" id="exc1">
        <option value="try">TRY</option>
        <option value="usd" selected>USD</option>
        <option value="eur">EUR</option>
        <option value="gbp">GBP</option>
      </select>
    </span>
  </div>
  <div class="input-group" style="margin-top:15px">
    <input type="text" id="prc2" class="form-control" placeholder="Sonuç" style="border:1px solid #ccc!important;padding:23px;" readonly>
    <span class="input-group-addon" style="width:25%;">
      <select class="form-control" id="exc2">
        <option value="try" selected>TRY</option>
        <option value="usd">USD</option>
        <option value="eur">EUR</option>
        <option value="gbp">GBP</option>
      </select>
    </span>
  </div>

  <!-- Döviz kutuları -->
  <div class="" style="margin-top:20px;">
    <div class="col-xs-4"><div class="panel panel-default text-center"><div class="panel-heading"><b>USD</b></div><div class="panel-body" id="usdBox"></div></div></div>
    <div class="col-xs-4"><div class="panel panel-default text-center"><div class="panel-heading"><b>EUR</b></div><div class="panel-body" id="eurBox"></div></div></div>
    <div class="col-xs-4"><div class="panel panel-default text-center"><div class="panel-heading"><b>GBP</b></div><div class="panel-body" id="gbpBox"></div></div></div>
  </div>
</div>

<script>
jQuery(document).ready(function () {
  // PHP'den gelen değerleri düzelt
  const rates = {
    try: 1,
    usd: parseFloat('<?php echo str_replace(",", ".", sprice($usd)); ?>') || 1,
    eur: parseFloat('<?php echo str_replace(",", ".", sprice($eur)); ?>') || 1,
    gbp: parseFloat('<?php echo str_replace(",", ".", sprice($gbp)); ?>') || 1
  };

  // Kutuları güncelle
  jQuery('#usdBox').text(rates.usd.toFixed(2));
  jQuery('#eurBox').text(rates.eur.toFixed(2));
  jQuery('#gbpBox').text(rates.gbp.toFixed(2));

  function exchange() {
    let prc1 = parseFloat(jQuery('#prc1').val().replace(",", ".")) || 0;
    let exc1 = jQuery('#exc1').val();
    let exc2 = jQuery('#exc2').val();

    if (exc1 && exc2) {
      let converted = prc1 * (rates[exc1] / rates[exc2]);
      jQuery('#prc2').val(converted.toFixed(2));
    }
  }

  // Girdi veya seçim değiştiğinde otomatik hesapla
  jQuery('#prc1, #exc1, #exc2').on('input change', exchange);

  // Sayfa yüklenince çalıştır
  exchange();
});
</script>

<?php }?>