<?php $helper = $this->getHelper() ?>
<?php $params = $this->getParams() ?>
<?php $exist = false ?>
<?php $child = null ?>
<div class="edit-static-form">
	
	<div class="line">
		<div class="col-des-12 builder-title">
			<h2><?php echo __('Single Product Block') ?></h2>
		</div>
	</div>
	<form id="section-form" enctype="multipart/form-data" method="POST" action="<?php echo $this->getUrl('fbuilder/element/save') ?>" data-hasrequired="<?php echo __('* Required Fields') ?>" data-mage-init='{"validation":{}}'>
		<input type="hidden" name="page_id" value="<?php echo $this->getRequest()->getParam('page_id') ?>">
		<input id="block_type" type="hidden" name="type" value="special_product">
		<input id="block_block_name" type="hidden" name="block_name" value="<?php echo $params['block'] ?>">
		<?php if(isset($params['id'])): ?>
			<?php 
				$child =  $this->getModel('MGS\Fbuilder\Model\Child')->load($params['id']);
				$exist = true;
				$settings = json_decode($child->getSetting(), true);
			?>
			<input type="hidden" name="child_id" value="<?php echo $params['id'] ?>">
		<?php endif ?>
		
		<div class="mgs-tab data items product" data-mage-init='{"tabs":{"openedState":"active"}}'>
			
			<?php 
				echo $this->getLayout()->createBlock('Magento\Framework\View\Element\Template')
					->setExist($exist)
					->setBuilderChild($child)
					->setDisableContent(1)
					->setBuilderHelper($helper)
					->setTemplate('MGS_Fbuilder::panel/create/element/widgets/general_tab.phtml')->toHtml() ;
			?>
			
			<div class="data item title" aria-labeledby="tab-label-additional-title" data-role="collapsible" id="tab-label-additional">
				<a class="data switch" tabindex="-1" data-toggle="switch" href="#additional" id="tab-label-additional-title">
					<?php echo __('Product Config') ?>
				</a>
			</div>
			
			<div class="data item content" id="additional" data-role="content" style="display:none">
				<div class="form-group line">
					<label for="ratio" class="col-tb-4 control-label"><?php echo __('Product') ?></label>
					<div class="col-tb-8">
						<div class="fbuilder-search-product">
							<input type="text" data-validate="{required:true}" data-mage-init='{"fbuilderSearch":{"formSelector":"#section-form", "url":"<?php echo $this->getUrl('fbuilder/index/search') ?>", "destinationSelector":"#product_autocomplete", "destinationText":"#product_temp", "destinationId":"#product"}}' autocomplete="off" aria-autocomplete="both" aria-haspopup="false" role="combobox" class="input-text" placeholder="<?php echo __('Enter product name to search.') ?>" id="product_temp" name="setting[product_name_temp]"<?php if($exist && isset($settings['product_name_temp'])): ?> value="<?php echo $settings['product_name_temp'] ?>"<?php endif ?>/>
							<input type="hidden" name="setting[product_id]" <?php if($exist && isset($settings['product_id'])): ?> value="<?php echo $settings['product_id'] ?>"<?php endif ?>id="product">
							<div id="product_autocomplete" class="search-autocomplete"></div>
						</div>
					</div>
				</div>
				
				<div class="form-group line">
					<label for="hide_name" class="col-tb-4 control-label"><?php echo __('Hide Product Name') ?></label>
					<div class="col-tb-8">
						<div class="admin__actions-switch" data-role="switcher">
							<input type="checkbox"<?php if($exist && $settings['hide_name']): ?> checked="checked"<?php endif ?> value="1" name="setting[hide_name]" id="hide_name" class="admin__actions-switch-checkbox">
							<label for="hide_name" class="admin__actions-switch-label">
								<span data-text-off="<?php echo __('No') ?>" data-text-on="<?php echo __('Yes') ?>" class="admin__actions-switch-text"></span>
							</label>
						</div>
					</div>
				</div>
				
				<div class="form-group line">
					<label for="hide_review" class="col-tb-4 control-label"><?php echo __('Hide Review') ?></label>
					<div class="col-tb-8">
						<div class="admin__actions-switch" data-role="switcher">
							<input type="checkbox"<?php if($exist && $settings['hide_review']): ?> checked="checked"<?php endif ?> value="1" name="setting[hide_review]" id="hide_review" class="admin__actions-switch-checkbox">
							<label for="hide_review" class="admin__actions-switch-label">
								<span data-text-off="<?php echo __('No') ?>" data-text-on="<?php echo __('Yes') ?>" class="admin__actions-switch-text"></span>
							</label>
						</div>
					</div>
				</div>
				
				<div class="form-group line">
					<label for="hide_price" class="col-tb-4 control-label"><?php echo __('Hide Price') ?></label>
					<div class="col-tb-8">
						<div class="admin__actions-switch" data-role="switcher">
							<input type="checkbox"<?php if($exist && $settings['hide_price']): ?> checked="checked"<?php endif ?> value="1" name="setting[hide_price]" id="hide_price" class="admin__actions-switch-checkbox">
							<label for="hide_price" class="admin__actions-switch-label">
								<span data-text-off="<?php echo __('No') ?>" data-text-on="<?php echo __('Yes') ?>" class="admin__actions-switch-text"></span>
							</label>
						</div>
					</div>
				</div>
				
				<div class="form-group line">
					<label for="hide_addcart" class="col-tb-4 control-label"><?php echo __('Hide Add to Cart') ?></label>
					<div class="col-tb-8">
						<div class="admin__actions-switch" data-role="switcher">
							<input type="checkbox"<?php if($exist && $settings['hide_addcart']): ?> checked="checked"<?php endif ?> value="1" name="setting[hide_addcart]" id="hide_addcart" class="admin__actions-switch-checkbox">
							<label for="hide_addcart" class="admin__actions-switch-label">
								<span data-text-off="<?php echo __('No') ?>" data-text-on="<?php echo __('Yes') ?>" class="admin__actions-switch-text"></span>
							</label>
						</div>
					</div>
				</div>
				
				<div class="form-group line">
					<label for="hide_addwishlist" class="col-tb-4 control-label"><?php echo __('Hide Add to Wishlist') ?></label>
					<div class="col-tb-8">
						<div class="admin__actions-switch" data-role="switcher">
							<input type="checkbox"<?php if($exist && $settings['hide_addwishlist']): ?> checked="checked"<?php endif ?> value="1" name="setting[hide_addwishlist]" id="hide_addwishlist" class="admin__actions-switch-checkbox">
							<label for="hide_addwishlist" class="admin__actions-switch-label">
								<span data-text-off="<?php echo __('No') ?>" data-text-on="<?php echo __('Yes') ?>" class="admin__actions-switch-text"></span>
							</label>
						</div>
					</div>
				</div>
				
				<div class="form-group line">
					<label for="hide_addcompare" class="col-tb-4 control-label"><?php echo __('Hide Add to Compare') ?></label>
					<div class="col-tb-8">
						<div class="admin__actions-switch" data-role="switcher">
							<input type="checkbox"<?php if($exist && $settings['hide_addcompare']): ?> checked="checked"<?php endif ?> value="1" name="setting[hide_addcompare]" id="hide_addcompare" class="admin__actions-switch-checkbox">
							<label for="hide_addcompare" class="admin__actions-switch-label">
								<span data-text-off="<?php echo __('No') ?>" data-text-on="<?php echo __('Yes') ?>" class="admin__actions-switch-text"></span>
							</label>
						</div>
					</div>
				</div>
				
				<div class="form-group line">
					<label for="hide_description" class="col-tb-4 control-label"><?php echo __('Hide short description') ?></label>
					<div class="col-tb-8">
						<div class="admin__actions-switch" data-role="switcher">
							<input type="checkbox"<?php if($exist && $settings['hide_description']): ?> checked="checked"<?php endif ?> value="1" name="setting[hide_description]" id="hide_description" class="admin__actions-switch-checkbox" onclick="useShortDescription()">
							<label for="hide_description" class="admin__actions-switch-label">
								<span data-text-off="<?php echo __('No') ?>" data-text-on="<?php echo __('Yes') ?>" class="admin__actions-switch-text"></span>
							</label>
						</div>
					</div>
				</div>
				
				<div class="form-group line" id="truncate_description">
					<label for="truncate" class="col-tb-4 control-label"><?php echo __('Truncate short description') ?></label>
					<div class="col-tb-8">
						<input type="text" class="input-text validate-number" id="truncate" name="setting[truncate]"<?php if($exist && isset($settings['truncate'])): ?> value="<?php echo $settings['truncate'] ?>"<?php endif ?>/>
					</div>
				</div>
			</div>
			
			<?php if($exist): ?>
				<?php 
					echo $this->getLayout()->createBlock('Magento\Framework\View\Element\Template')
						->setExist($exist)
						->setBuilderChild($child)
						->setBuilderHelper($helper)
						->setTemplate('MGS_Fbuilder::panel/create/element/widgets/code_tab.phtml')->toHtml() ;
				?>
				
			<?php endif ?>
		</div>
		
		
		<div class="line">
			<div class="form-group">
				<div class="col-des-12 builder-action">
					<div class="buttons">
						<?php if(!$exist): ?>
							<button type="button" class="action" onclick="history.go(-1)"><span><?php echo __('Back') ?></span></button>
						<?php endif ?>
						<button type="submit" class="action primary"><span><?php echo __('Submit') ?></span></button>
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">
	require([
		'jquery',
	], function(jQuery){
		(function($) {
			$(document).ready(function(){
				useShortDescription();
			});
		})(jQuery);
	});
	
	function useShortDescription(){
		require([
			'jquery',
		], function(jQuery){
			(function($) {
				if($('#hide_description').prop("checked") == true){
					$('#truncate_description').hide();
				}else{
					$('#truncate_description').show();
				}
			})(jQuery);
		});
	}
</script>