<div class="content-wrapper">
  <section class="content-header">
    <h1>
       <?= $pTitle ?>
        <small><?= $pDescription ?></small>
    </h1>
    <ol class="breadcrumb">
     <li><a href="<?= base_url() ?>"><i class="fa fa-star-o" aria-hidden="true"></i>Home</a></li>
     <li><?= $menu ?></li>
     <li class="active"><?= $smenu ?></li>
    </ol>
  </section>
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <?php 
        $url = 'Issue/createMechIssue';
        $edit = 0;
        $issue_id = (isset($issue_id) && !empty($issue_id))?$issue_id:'';
        $mechanic_id = (isset($mechanic_id) && !empty($mechanic_id))?$mechanic_id:'';
        if(!empty($mechanic_id) && !empty($issue_id)){
          $edit = 1;
          $url = 'Issue/updateMechIssue/'.$mechanic_id.'/'.$issue_id;
        }
        if($this->session->flashdata('message')) { 
          $flashdata = $this->session->flashdata('message'); ?>
          <div class="alert alert-<?= $flashdata['class'] ?>">
            <button class="close" data-dismiss="alert" type="button">×</button>
            <?= $flashdata['message'] ?>
          </div>
        <?php } ?>
      </div>
      <div class="col-md-12">
        <div class="box box-warning">
          <div class="box-body">
            <form role="form" action="<?= base_url($url) ?>" method="post" 
              class="validate" data-parsley-validate="" enctype="multipart/form-data">
              <div class="col-md-12">
              	<div class="col-md-6">
                  <div class="form-group">
                    <label>General Issue</label>
                    <select name="issue_id" class="form-control required <?= ($edit)?'prevent-click':'' ?>" placeholder="Select General Issue" required="">
                      <option selected disabled>Choose an Issue Type</option>
              			  <?php 
              			  if(!empty($issue_data)){ 
  	                    foreach ($issue_data as $issue) {
  	                      $select = '';
                          if(isset($issue_id) && $issue->issue_id == decode_param($issue_id)){
                            $select = 'selected';
                          }
  	                      echo '<option '.$select.' value="'.encode_param($issue->issue_id).'">'
                                  .$issue->issue.
                               '</option>';
  	                    }
                 		  } ?>
                    </select> 
                  </div>
                </div>
                <?php
                $dChkFlg=($edit)?'':'checked';
                $customFlag=(isset($mechanicIssueData['custom_enable']))?$mechanicIssueData['custom_enable']:'';
                ?>
                <div class="col-md-6">
                  <div class="form-group marginTop23 <?= ($edit && !empty($mechanicIssueData['sub_issue']))?'':'hide' ?>" id="mapTypeCntr">
                    <input type="radio" name="mapping_type" <?=($customFlag==0)?'checked':$dChkFlg?> value="0">
                      <label class="padAll-10">Use Default</label>
                    <input type="radio" name="mapping_type" <?=($customFlag==1)?'checked':''?> value="1">
                      <label class="padAll-10">Use Custom</label>
                  </div>
                  <div class="form-group noSubTypeMsg <?= ($edit && empty($mechanicIssueData['sub_issue']))?'':'hide' ?>" id="showNoSubTypeMsg">
                    <span>
                      Issue doesn't have a sub category, you can directly map it through submitting...!
                    </span>
                  </div>
                </div>
          	  </div>
              <div class="col-md-12"> 
                <div class="<?= ($edit && !empty($mechanicIssueData['sub_issue']))?'':'hide' ?>" id="subTypeDtlsCntr">
                  <div class="col-md-12 padBottom10">
                    <label>Issue Sub Type Details</label>
                  </div>
                  <div id="subTypeDtlsCntrData">
                  <?php 
                    $disabled = 'disabled';
                    $inputCls = 'custom-input';
                    $txtAreaCls = 'custom-textarea';
                    if($customFlag){
                      $disabled = '';
                      $inputCls = '';
                      $txtAreaCls = '';
                    }
                    if($edit && !empty($mechanicIssueData['sub_issue'])) { 
                      foreach($mechanicIssueData['sub_issue'] AS $issue_cat_id => $sub_issue) { ?>
                        <div class="col-md-12">
                          <div class="col-md-1"></div>
                          <div class="col-md-1 marginTop5">
                            <i class="fa fa-arrow-circle-right fav-add-icon"></i>
                          </div>
                          <div class="col-md-2">
                            <label><?= $sub_issue['issue_category'] ?></label>
                          </div>
                          <div class="col-md-2 marginBottom-10">
                            <img class="small-icon" src="<?= base_url($sub_issue['issue_cat_image']) ?>"
                              onerror="this.src='<?= base_url('assets/images/no_image_text.png') ?>';" />
                          </div>
                          <div class="col-md-4 marginBottom-10">
                            <textarea name="default_description_<?= $issue_cat_id ?>" <?= $disabled ?> required class="custom-textarea-style <?= $txtAreaCls ?>"><?= $sub_issue['description'] ?></textarea>
                          </div>
                          <div class="col-md-2">
                            Service Fee : 
                            <input name="default_service_fee_<?= $issue_cat_id ?>" <?= $disabled ?> required data-parsley-pattern="^[0-9\ . \/]+$" class="custom-input-style <?= $inputCls ?>" maxlength="6" value="<?= $sub_issue['service_fee'] ?>">
                          </div>
                        </div>
                        <input type="hidden" name="issue_cat_ids[]" value="<?= $issue_cat_id ?>">
                    <?php } } ?>
                  </div>
                </div> 
              </div> 
              <div class="col-md-12 marginTop10">
                <div class="box-footer textCenterAlign">
                  <button type="submit" class="btn btn-primary">Submit</button>
                  <a href="<?= base_url('Issue/viewMappedIssues/'.encode_param($mechanic_id)) ?>" class="btn btn-primary">Cancel</a>
                </div>
              </div>
              <input type="hidden" name="mechanic_id" value="<?= $mechanic_id ?>" >       
            </form>
          </div>
        </div>
      </div>
    </div>
  </section>
</div>