<?php 
defined('_JEXEC') or die('Restricted access');
/**
* @package OS CCK
* @copyright 2020 OrdaSoft.
* @author Andrey Kvasnevskiy(akbet@mail.ru),Roman Akoev (akoevroman@gmail.com)
* @link http://ordasoft.com/cck-content-construction-kit-for-joomla.html
* @description OrdaSoft Content Construction Kit
*/
//$dispatcher = JDispatcher::getInstance();
//        $plugin_name = 'stripe';
//        $plugin = JPluginHelper::importPlugin( 'payment',$plugin_name);
//        $pay_form = $dispatcher->trigger('getHTMLPayPal', array('111111111'));
//        echo $pay_form[0];
//require_once JPATH_SITE. '/components/com_os_cck/stripe-php/init.php';
//\Stripe\Stripe::setApiKey('sk_test_51HIBzmBuAyxWNDQIapDwYhcigkbHqAsfhLOUNKUzy1htJVcUJA4b3EGLfSUHi41w5fsk9ElQLkpBIhmabjsuW4s700ro8xwvqL');
//
//\Stripe\PaymentIntent::create([
//  'amount' => 1000,
//  'currency' => 'usd',
//  'payment_method_types' => ['card'],
//  'receipt_email' => 'jenny.rosen@example.com',
//]);
//$request = array(
////                  "api_key" => 'sk_test_51HIBzmBuAyxWNDQIapDwYhcigkbHqAsfhLOUNKUzy1htJVcUJA4b3EGLfSUHi41w5fsk9ElQLkpBIhmabjsuW4s700ro8xwvqL',
//    
//                  "amount" => 20,
//                  "currency" => 'usd',
////                  "PWD" => $vars['paypal_pro_password'], 
////                  "TRXTYPE" => "A",
////                  "AMT" => (float) $vars['price'],
////                  "CURRENCY" => $vars['currency_code'],
////                  "CREATESECURETOKEN" => $vars['paypal_secure_token'],
////                  "SECURETOKENID" => uniqid('MySecTokenID-'), //Should be unique, never used before
////                  "item_name" => $vars['item_name'],
////                  "item_number" => $vars['item_number'],
////                  "RETURNURL" => $vars['return_url'],
////                  "CANCELURL" => $vars['cancel_url'],
////                  "ERRORURL" => $vars['notify_url'],
////                  "SILENTPOSTURL" => $vars['notify_url'],
////                  
////                  "cmd" => "_xclick",
////                  "business" => $vars['paypal_email'],
////                  "CSCREQUIRED" => 'TRUE',
//
//                );
//$paramList = array();
//foreach($request as $index => $value) {
//    $paramList[] = $index . "=" . $value;
//}
////            var_dump($paramList);
//$apiStr = implode("&", $paramList);
////$apiStr = implode("&", $request);
//var_dump($apiStr);
////$curl = curl_init('https://api.stripe.com/v1/charges/ca_Hrvyj55ZR9rxvME9PVzAxkBg2glk0dCt');
//$curl = curl_init('https://api.stripe.com/v1/charges');
//            curl_setopt($curl, CURLOPT_USERPWD, 'sk_test_51HIBzmBuAyxWNDQIapDwYhcigkbHqAsfhLOUNKUzy1htJVcUJA4b3EGLfSUHi41w5fsk9ElQLkpBIhmabjsuW4s700ro8xwvqL:');
//            curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
//
//            // If you get connection errors, it may be necessary to uncomment
//            // the following two lines:
//            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
//            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
//
//            curl_setopt($curl, CURLOPT_POST, TRUE);
//            //curl_setopt($curl, CURLOPT_POSTFIELDS, $apiStr);
//
//            $result = curl_exec($curl);
//            var_dump($result);
//curl https://api.stripe.com/v1/charges \
//  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
//curl https://api.stripe.com/v1/charges \
//  -u sk_test_51HIBzmBuAyxWNDQIapDwYhcigkbHqAsfhLOUNKUzy1htJVcUJA4b3EGLfSUHi41w5fsk9ElQLkpBIhmabjsuW4s700ro8xwvqL:
$doc->addStyleSheet(JUri::root() . 'components/com_os_cck/assets/css/front_end_style.css');

$field = new stdClass();
$field->db_field_name = 'form-'.$layout->lid;
$form_hover_animation = get_field_hover_animation($field, $layout);

?>

<div class="cck-body instance_body instance_body_<?php echo $layout->lid; ?>" eiid="<?php echo $entityInstance->eiid; ?>" eid="<?php echo $entityInstance->fk_eid; ?>" cid="<?php echo isset($category->cid) ? $category->cid : ''; ?>" <?php echo $form_hover_animation; ?>>
  
  <?php

  JPluginHelper::importPlugin('content');
//  $dispatcher = JDispatcher::getInstance();

  $Itemid .= ($moduleId) ? '&moduleId=' . $moduleId : '';
  
  if($layout->layout_html !== null){
    $layout_html = urldecode($layout->layout_html);
  }else{
      $layout_html = '';
  }
  $layout_html = cut_params($layout_html);
  $layout_html = remove_admin_classes($layout_html);
  if(isset($layout_params['views']['show_layout_title']) && $layout_params['views']['show_layout_title'])
  {
    echo "<h3>";
      echo $layout_params['views']['layout_title'];
    echo "</h3>";
  }

  $field = new stdClass();
  $field->db_field_name = 'form-'.$layout->lid;
  $form_styling = get_field_styles($field, $layout);
  $field_from_params = $layout_params["fields"];
  //var_dump($field_from_params);
  $form_custom_class = get_field_custom_class($field, $layout);
  $form_offset_animation = get_field_offset_animation($field, $layout);
  
  
  $fields_list = $layout->field_list;
  //var_dump($fields_list);
  //add child selects to layout
  $addChildSelectToLayout = addChildSelectToLayout($fields_list, $entityInstance, $layout_params, $layout_html, $layout);
  $layout_html = $addChildSelectToLayout['layout_html'];
  //$layout_html = str_replace('hide-field-name', 'hide_field_name ', $layout_html);
  $layout_params = $addChildSelectToLayout['layout_params'];
  $parent = $addChildSelectToLayout['select_parent'];
  $layout->params = serialize($layout_params);
  $hover_animated = array();
  //add child selects to layout
  $child_entities = (isset($layout_params['child_entities'])) ? $layout_params['child_entities'] : '';

  
//  var_dump($category);
  ?>
  <!--Начало табов-->
  <div class="<?php echo $form_custom_class; ?> instance_block" <?php echo $form_offset_animation; ?> <?php echo $form_hover_animation; ?> <?php echo $form_styling; ?> >
      <?php
        //var_dump($entityInstance->_field_value_list);
//      for ($i = 0, $hover_item = 0, $nnn = count($fields_list); $i < $nnn; $i++) {
        $layout_html = $layout->getLayoutViews($entityInstance, $fields_list, $layout_html, $layout_params, $hover_animated, $option, $child_entities, $moduleId, $Itemid, $recursive_count, 0, $category);
        echo $layout_html; 
      ?>
  </div>
</div>
<script type="text/javascript">
  window.addEventListener('load', function() {
    addBookCalListener();
  })
  function addBookCalListener(){
      jQuerOs('.booking_calendar_next form[name=calendar] input[value=Next], .booking_calendar_previous form[name=calendar] input[value=Previous]').click(function(){
          event.preventDefault();
          changeBookingCalendarAjax(this, '<?php echo JURI::root(); ?>')
          // console.log('3333333333333', this)
      })
  }
  loadInstance();
</script>
