<?php
 
 /**
 * =============================================================================
 * @package         Blue Raven (Free Version)
 * @Plugin URI      https://enterrahost.com/plugins/blue-raven
 * 
 * @Author          EnterraHost
 * @Author URI      https://enterrahost.com
 * @License         GPL-2.0-or-later
 *  
 * @Copyright       (c) 2025 EnterraHost
 * @Contents        Generates a dynamic product attribute row with name, values, visibility, and variation checkboxes, using WordPress coding standards.
 *
 * =============================================================================
 * 
 * || INDEX:
 * ||   - ATTRIBUTE ROW
 * || 
 * =============================================================================
 */

if ( ! defined( 'ABSPATH' ) ) exit; 

/*
============================================================
    ATTRIBUTE ROW
============================================================
*/

$name = isset($attribute['name']) ? esc_attr($attribute['name']) : '';
$values = isset($attribute['values']) ? esc_attr(implode(' | ', $attribute['values'])) : '';
$visible_checked = !empty($attribute['visible']);
$variations_checked = !empty($attribute['variations']);
$currentRowIndex = (int) $index + 1;

?>
<tr>
    <td class="col-name">
        <input type="text" class="br-input" style="width:100%;" name="attribute_name_<?php echo esc_attr($currentRowIndex); ?>" placeholder="<?php echo esc_attr__('Attribute Name', 'blue-raven'); ?>" value="<?php echo esc_attr($name); ?>">
    </td>
    <td class="col-values">
        <input type="text" class="file-url br-input" style="width:100%;" name="attribute_value_<?php echo esc_attr($currentRowIndex); ?>" placeholder="<?php esc_attr_e('Enter options for customers to choose from, e.g., Blue or Large. Use | to separate options.', 'blue-raven'); ?>" value="<?php echo esc_attr($values); ?>">
    </td>
    <td class="col-visible">
        <label class="br-checkbox spacing-right" style="width: 50%;">
            <input type="checkbox" value="visible" style="display: none;" id="attribute_check_<?php echo esc_attr($currentRowIndex); ?>" name="attribute_check_<?php echo esc_attr($currentRowIndex); ?>" <?php checked($visible_checked); ?>>
            <span class="br-check-mark"></span>
            <label for="attribute_check_<?php echo esc_attr($currentRowIndex); ?>"></label>
        </label>
    </td>
    <td class="col-variations">
        <label class="br-checkbox spacing-right" style="width: 50%;">
            <input type="checkbox" value="variations" style="display: none;" id="attribute_variations_<?php echo esc_attr($currentRowIndex); ?>" name="attribute_variations_<?php echo esc_attr($currentRowIndex); ?>" <?php checked($variations_checked); ?>>
            <span class="br-check-mark"></span>
            <label for="attribute_variations_<?php echo esc_attr($currentRowIndex); ?>"></label>
        </label>
    </td>
    <td>
        <button type="button" class="remove-attribute text-button" data-row-index="<?php echo esc_attr($currentRowIndex); ?>">❌</button>
    </td>
</tr>
    
    