<?php
  $form_url = user_url("brands/store/invoice");
  $redirect_url = user_url('invoice');
  $form_attributes = array('class' => 'form actionForm', 'data-redirect' => $redirect_url, 'method' => "POST");
  $form_hidden = [
    'type' => 'invoice',
    'id'   => @$item['id'],
  ];
  $config_status = app_config('config')['status'];
  $class_element = app_config('template')['form']['class_element'];
  $class_element_editor = app_config('template')['form']['class_element_editor'];
  $class_element_select = app_config('template')['form']['class_element_select'];

  $current_config_status = (in_array($controller_name, $config_status)) ? $config_status[$controller_name] : $config_status['default'];
  $form_status = array_intersect_key(app_config('template')['status'], $current_config_status);
  $form_status = array_combine(array_keys($form_status), array_column($form_status, 'name'));
  
  $payment_status = [
    '' => 'Select one',
    '0' => 'Unpaid',
    '1' => 'Pending',
    '2' => 'Paid',
  ];
  $form_items2 = array_combine(array_column($item2, 'id'), array_column($item2, 'brand_name'));

  // ইনপুট ফিল্ড ও ড্রপডাউনকে স্লিম ও সিম্পল করার ক্লাস
  $custom_input_class = $class_element . " rounded-2 custom-form-input";
  $custom_select_class = $class_element_select . " rounded-2 custom-form-select brand";
  $custom_textarea_class = $class_element . " rounded-2 custom-form-input";

  $general_elements = [
    [
      'label'      => form_label('Amount', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_input(['name' => 'customer_amount', 'value' => @$item['customer_amount'], 'type' => 'number', 'class' => $custom_input_class, 'style' => 'height: 38px; font-size: 13px; border: 1px solid #e2e8f0;']),
      'class_main' => "col-md-6 col-sm-12 mb-3",
    ],
    [
      'label'      => form_label('User Brand', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_dropdown('brand_id', $form_items2, @$item['brand_id'], ['class' => $custom_select_class, 'style' => 'height: 38px; font-size: 13px; border: 1px solid #e2e8f0;']),
      'class_main' => "col-md-6 col-sm-12 mb-3",
    ],
    [
      'label'      => form_label('Status', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_dropdown('status', $form_status, @$item['status'], ['class' => $custom_select_class, 'style' => 'height: 38px; font-size: 13px; border: 1px solid #e2e8f0;']),
      'class_main' => "col-md-6 col-sm-12 mb-3",
    ],
    [
      'label'      => form_label('Payment Status', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_dropdown('pay_status', $payment_status, !empty($item['pay_status']) ? $item['pay_status'] : '0', ['class' => $custom_select_class, 'style' => 'height: 38px; font-size: 13px; border: 1px solid #e2e8f0;']),
      'class_main' => "col-md-6 col-sm-12 mb-3",
    ],
    [
      'label'      => form_label('Customer Name', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_input(['name' => 'customer_name', 'value' => @$item['customer_name'], 'type' => 'text', 'class' => $custom_input_class, 'style' => 'height: 38px; font-size: 13px; border: 1px solid #e2e8f0;']),
      'class_main' => "col-md-12 col-sm-12 mb-3",
    ],
    [
      'label'      => form_label('Customer Number', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_input(['name' => 'customer_number', 'value' => @$item['customer_number'], 'type' => 'text', 'class' => $custom_input_class, 'style' => 'height: 38px; font-size: 13px; border: 1px solid #e2e8f0;']),
      'class_main' => "col-md-12 col-sm-12 mb-3",
    ],
    [
      'label'      => form_label('Customer Email', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_input(['name' => 'customer_email', 'value' => @$item['customer_email'], 'type' => 'text', 'class' => $custom_input_class, 'style' => 'height: 38px; font-size: 13px; border: 1px solid #e2e8f0;']),
      'class_main' => "col-md-12 col-sm-12 mb-3",
    ],
    [
      'label'      => form_label('Customer Address', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_textarea(['name' => 'customer_address', 'rows' => '2', 'value' => @$item['customer_address'], 'class' => $custom_textarea_class, 'style' => 'font-size: 13px; border: 1px solid #e2e8f0; padding: 8px 12px;']),
      'class_main' => "col-md-12 col-sm-12 mb-3",
    ],
    [
      'label'      => form_label('Description', '', ['class' => 'text-secondary small fw-medium mb-1']),
      'element'    => form_textarea(['name' => 'customer_description', 'rows' => '2', 'value' => @$item['customer_description'], 'class' => $custom_textarea_class, 'style' => 'font-size: 13px; border: 1px solid #e2e8f0; padding: 8px 12px;']),
      'class_main' => "col-md-12 col-sm-12 mb-3",
    ],
  ];

  $data['modal_title'] = 'Invoice';
?>

<?= view('layouts/common/modal/modal_top', $data); ?>

<?php echo form_open($form_url, $form_attributes, $form_hidden); ?>
<div class="modal-body px-4 py-3">
    <div class="row">
        <?php echo render_elements_form($general_elements); ?>
    </div>
</div>

<div class="modal-footer px-4 py-3 border-top-0 d-flex justify-content-end gap-2" style="background-color: #ffffff;">
    <?= modal_buttons(); ?>
</div>

<?php echo form_close(); ?>

<?= view('layouts/common/modal/modal_bottom'); ?>

<style>
    /* সিম্পল ফর্ম ফোকাস স্টাইল */
    .custom-form-input:focus, .custom-form-select:focus {
        border-color: #3b82f6 !important;
        box-shadow: none !important;
        background-color: #fff !important;
    }
</style>
