<div class="content-wrapper">
   <div class="container-full">
      <!-- Content Header (Page header) -->	  
      <div class="content-header">
         <div class="d-flex align-items-center">
            <div class="me-auto">
               <h4 class="page-title">Blog Management</h4>
               <div class="d-inline-block align-items-center">
                  <nav>
                     <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#"><i class="fa fa-home"></i></a></li>
                        <li class="breadcrumb-item active" aria-current="page">Blog</li>
                     </ol>
                  </nav>
               </div>
            </div>
         </div>
      </div>
      <!-- Main content -->
      <section class="content">
         <?php if ($this->session->flashdata('success')) { ?>
         <div class="alert alert-success">
            <a href="<?= base_url('admin/blog'); ?>" class="close" data-dismiss="alert" aria-label="close">×</a>
            <strong><?php echo $this->session->flashdata('success'); ?></strong>
         </div>
         <?php } ?>
         <?php if ($this->session->flashdata('error')) { ?>
         <div class="alert alert-danger">
            <a href="<?= base_url('admin/blog'); ?>" class="close" data-dismiss="alert" aria-label="close">×</a>
            <strong><?php echo $this->session->flashdata('error'); ?></strong>
         </div>
         <?php } ?>
         <div class="row">
            <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
               <div class="box">
                  <!-- /.box-header -->
                  <?php if(empty($blogE->blog_id)){ ?>
                  <div class="d-flex" style="display: flex !important;justify-content: space-between; align-items: center;padding: 0 20px 0 0;border-bottom: 1px solid #f0f3f6;">
                     <div class="box-header with-border">
                        <h4 class="box-title">Add Blog</h4>
                     </div>
                     <a href="<?= base_url(); ?>admin/blog" class="btn btn-primary"><i class="fa-solid fa-plus"></i>Blog List</a>
                  </div>
                  <form class="form" action="<?= base_url('admin/blog-add-action'); ?>" method="post" enctype="multipart/form-data">
                     <div class="box-body">
                        <div class="row">
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="form-label">Title<span class="reqired-star">*</span></label>
                                 <input type="text" class="form-control" name="blog_title" required>
                              </div>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="form-label">Short Description<span class="reqired-star">*</span></label>
                                 <textarea class="form-control" placeholder="Description ..." rows="2" name="blog_short_description" required></textarea>
                              </div>
                           </div>
                            <div class="col-md-12">
                              <div class="form-group">
                                 <label class="form-label">Description<span class="reqired-star">*</span></label>
                                 <textarea class="form-control" placeholder="Description ..." rows="2" id="editor1" name="blog_description" required></textarea>
                              </div>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group"><br>
                                 <label class="form-label">Image<span class="reqired-star">*</span></label>
                                 <input type="file" id="file" name="blog_image" required>
                              </div>
                           </div>
                           <div class="col-md-6">
                              <div class="form-group">
                                 <label class="form-label">Meta Title</label>
                                 <input type="text" class="form-control" name="meta_title" >
                              </div>
                           </div>
                           <div class="col-md-6">
                              <div class="form-group">
                                 <label class="form-label">Meta Keyword</label>
                                 <input type="text" class="form-control" name="meta_keyword" >
                              </div>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="form-label">Meta Description</label>
                                 <textarea class="form-control" placeholder="Description ..." rows="2"  name="meta_description" ></textarea>
                              </div>
                           </div>
                        </div>
                     </div>
                     <!-- /.box-body -->
                     <div class="box-footer">
                        <button type="submit" class="btn btn-primary">Save</button>
                     </div>
                  </form>
                  <?php }else{ ?>
                  <div class="box-header with-border">
                     <h4 class="box-title">Update Blog</h4>
                  </div>
                  <form class="form" action="<?= base_url('admin/blog-update'); ?>" method="post" enctype="multipart/form-data">
                     <div class="box-body">
                        <div class="row">
                           <div class="col-md-6">
                              <div class="form-group">
                                 <label class="form-label">Title<span class="reqired-star">*</span></label>
                                 <input type="hidden" class="form-control" name="blog_id" value="<?= $blogE->blog_id; ?>" required>
                                 <input type="text" class="form-control" name="blog_title" value="<?= $blogE->blog_title; ?>" required>
                              </div>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="form-label">Short Description<span class="reqired-star">*</span></label>
                                 <textarea class="form-control" placeholder="Description ..." rows="2" name="blog_short_description" ><?= $blogE->blog_short_description; ?></textarea>
                              </div>
                           </div>
                            <div class="col-md-12">
                              <div class="form-group">
                                 <label class="form-label">Description<span class="reqired-star">*</span></label>
                                 <textarea class="form-control" placeholder="Description ..." rows="2" id="editor1" name="blog_description"><?= $blogE->blog_description; ?></textarea>
                              </div>
                           </div>
                           
                           <div class="col-md-12">
                            <div class="form-group"><br>
                                <label class="form-label">Image<span class="reqired-star">*</span></label>
                                <!-- Show existing image -->
                                <img src="<?= base_url('uploads/blog/' . $blogE->blog_image); ?>" width="100">
                                <!-- Preserve existing image filename -->
                                <input type="hidden" name="existing_image" value="<?= $blogE->blog_image; ?>">
                                <!-- Optional new image upload -->
                                <input type="file" id="blog_image" name="blog_image">
                            </div>
                        </div>
                       
                           <div class="col-md-6">
                              <div class="form-group">
                                 <label class="form-label">Meta Title</label>
                                 <input type="text" class="form-control" name="meta_title" >
                              </div>
                           </div>
                           <div class="col-md-6">
                              <div class="form-group">
                                 <label class="form-label">Meta Keyword</label>
                                 <input type="text" class="form-control" name="meta_keyword" >
                              </div>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="form-label">Meta Description</label>
                                 <textarea class="form-control" placeholder="Description ..." rows="2"  name="meta_description" ></textarea>
                              </div>
                           </div>
                           <div class="col-md-12">
                              <div class="form-group">
                                 <label class="form-label">Status</label>
                                 <select class="form-select" name="blog_status">
                                    <option value="1" <?php if($blogE->blog_status == 1 ){ echo "selected";}else{} ?>>Active</option>
                                    <option value="0" <?php if($blogE->blog_status == 0 ){ echo "selected";}else{} ?>>Inactive</option>
                                 </select>
                              </div>
                           </div>
                        </div>
                     </div>
                     <!-- /.box-body -->
                     <div class="box-footer">
                        <button type="submit" class="btn btn-primary">Update</button>
                     </div>
                  </form>
                  <?php } ?> 
               </div>
            </div>
            <!-- /.box -->			
         </div>
      </section>
      <!-- /.content -->
   </div>
</div>