<?php defined('MW_PATH') || exit('No direct script access allowed');

/**
 * This file is part of the MailWizz EMA application.
 * 
 * @package MailWizz EMA
 * @author Serban George Cristian <cristian.serban@mailwizz.com> 
 * @link http://www.mailwizz.com/
 * @copyright 2013-2014 MailWizz EMA (http://www.mailwizz.com)
 * @license http://www.mailwizz.com/license/
 * @since 1.0
 */
 
?>

<div class="pull-left">
    <?php $this->widget('customer.components.web.widgets.MailListSubNavWidget', array(
        'list' => $list,
    ))?>
</div>
<div class="clearfix"><!-- --></div>
<hr />

<?php $form = $this->beginWidget('CActiveForm'); ?>
<div class="panel panel-default">
    
    <div class="panel-heading">
        <div class="pull-left">
            <h3 class="panel-title">
                <span class="glyphicon glyphicon-list-alt"></span> <?php echo $pageHeading;?>
            </h3>
        </div>
        <div class="pull-right"></div>
        <div class="clearfix"><!-- --></div>
    </div>
    
    <div class="panel-body">
        
        <div class="form-group col-lg-6">
            <?php echo $form->labelEx($segment, 'name');?>
            <?php echo $form->textField($segment, 'name', $segment->getHtmlOptions('name')); ?>
            <?php echo $form->error($segment, 'name');?>
        </div>    
        
        <div class="form-group col-lg-6">
            <?php echo $form->labelEx($segment, 'operator_match');?>
            <?php echo $form->dropDownList($segment, 'operator_match', $segment->getOperatorMatchArray(), $segment->getHtmlOptions('operator_match')); ?>
            <?php echo $form->error($segment, 'operator_match');?>
        </div>
        
        <div class="clearfix"><!-- --></div>
        
        <div class="conditions-container">
            <h5><?php echo Yii::t('list_segments', 'Defined conditions:');?></h5>
            <?php if (!empty($conditions)) { foreach ($conditions as $index => $cond) {?>
            <div class="item">
                <hr />
                <div class="form-group col-lg-3">
                    <?php echo CHtml::activeLabelEx($cond, 'field_id');?>
                    <?php echo CHtml::dropDownList($cond->modelName.'['.$index.'][field_id]', $cond->field_id, $segment->getFieldsDropDownArray(), $cond->getHtmlOptions('field_id')); ?>
                    <?php echo CHtml::error($cond, 'field_id');?>
                </div>
                <div class="form-group col-lg-3">
                    <?php echo CHtml::activeLabelEx($cond, 'operator_id');?>
                    <?php echo CHtml::dropDownList($cond->modelName.'['.$index.'][operator_id]', $cond->operator_id, $cond->getOperatorsDropDownArray(), $cond->getHtmlOptions('operator_id')); ?>
                    <?php echo CHtml::error($cond, 'operator_id');?>
                </div>
                <div class="form-group col-lg-3">
                    <?php echo CHtml::activeLabelEx($cond, 'value');?>
                    <?php echo CHtml::textField($cond->modelName.'['.$index.'][value]', $cond->value, $cond->getHtmlOptions('value')); ?>
                    <?php echo CHtml::error($cond, 'value');?>
                </div>
                <div class="form-group col-lg-3">
                    <label><?php echo Yii::t('app', 'Action');?></label><br />
                    <a href="javascript:;" class="btn btn-danger btn-remove-condition"><?php echo Yii::t('list_segments', 'Remove condition');?></a>
                </div>
                <div class="clearfix"><!-- --></div>
            </div>
            <?php }} ?> 
        </div>
        
        <hr />
        
        <div class="col-lg-6"><!-- --></div>
        <div class="col-lg-6">
            <a href="javascript:;" class="pull-right btn btn-default btn-add-condition"><?php echo Yii::t('list_segments', 'Add condition');?></a>
        </div>
        
        <div class="clearfix"><!-- --></div>
        <div class="subscribers-wrapper" style="display: none;">
            <h5><?php echo Yii::t('list_segments', 'Subscribers matching your segment:');?></h5>
            <hr />
            <div id="subscribers-wrapper"></div>
        </div>
        <div class="clearfix"><!-- --></div>
        
    </div>
    
    <div class="panel-footer">
        <div class="pull-right">
            <?php if (!$segment->isNewRecord && !empty($conditions)) { ?>
            <a href="<?php echo $this->createUrl('list_segments/subscribers', array('list_uid' => $list->list_uid, 'segment_uid' => $segment->segment_uid));?>" class="btn btn-default btn-submit btn-show-segment-subscribers" data-loading-text="<?php echo Yii::t('app', 'Please wait, processing...');?>"><?php echo Yii::t('app', 'Show matching subscribers');?></a>
            <?php } ?>
            <button type="submit" class="btn btn-default btn-submit" data-loading-text="<?php echo Yii::t('app', 'Please wait, processing...');?>"><?php echo Yii::t('app', 'Save changes');?></button>
        </div>
        <div class="clearfix"><!-- --></div>
    </div>
    
</div>
<?php $this->endWidget(); ?>

<div id="condition-template" style="display: none;">
    <div class="item">
        <hr />
        <div class="form-group col-lg-3">
            <?php echo CHtml::activeLabelEx($condition, 'field_id');?>
            <?php echo CHtml::dropDownList($condition->modelName.'[{index}][field_id]', $condition->field_id, $segment->getFieldsDropDownArray(), $condition->getHtmlOptions('field_id')); ?>
            <?php echo CHtml::error($condition, 'field_id');?>
        </div>
        <div class="form-group col-lg-3">
            <?php echo CHtml::activeLabelEx($condition, 'operator_id');?>
            <?php echo CHtml::dropDownList($condition->modelName.'[{index}][operator_id]', $condition->operator_id, $condition->getOperatorsDropDownArray(), $condition->getHtmlOptions('operator_id')); ?>
            <?php echo CHtml::error($condition, 'operator_id');?>
        </div>
        <div class="form-group col-lg-3">
            <?php echo CHtml::activeLabelEx($condition, 'value');?>
            <?php echo CHtml::textField($condition->modelName.'[{index}][value]', $condition->value, $condition->getHtmlOptions('value')); ?>
            <?php echo CHtml::error($condition, 'value');?>
        </div>
        <div class="form-group col-lg-3">
            <label><?php echo Yii::t('app', 'Action');?></label><br />
            <a href="javascript:;" class="btn btn-danger btn-remove-condition"><?php echo Yii::t('list_segments', 'Remove condition');?></a>
        </div>
        <div class="clearfix"><!-- --></div>
    </div>
</div>