<?php

namespace DropshippingXmlFreeVendor;

use DropshippingXmlFreeVendor\WPDesk\Library\DropshippingXmlCore\Form\Fields\Component\AcfGroupComponent;
/**
 * @var AcfGroupComponent $field
 * @var \WPDesk\View\Renderer\Renderer $renderer
 * @var string $name_prefix
 * @var array|string $value
 */
$name_prefix = $name_prefix . '[' . $field->get_name() . ']';
$get_value = static function (string $field_key) use ($value): string {
    if (\is_array($value) && isset($value[$field_key])) {
        return (string) $value[$field_key];
    }
    return '';
};
$acf_input_type = static function (string $type): string {
    $types = ['textarea' => 'textarea'];
    return $types[$type] ?? 'text';
};
?>
<div class="group-switch group-closed">
	<h3 class="group-switcher">
		<span><?php 
echo \esc_html($field->get_group_title());
?></span>
		<span class="group-arrow dashicons dashicons-arrow-down"></span>
	</h3>
	<div class="inside">
		<?php 
foreach ($field->get_acf_fields() as $acf_field) {
    ?>
			<?php 
    if (!\is_array($acf_field)) {
        continue;
    }
    $acf_key = (string) ($acf_field['key'] ?? '');
    $acf_name = (string) ($acf_field['name'] ?? $acf_key);
    $acf_label = (string) ($acf_field['label'] ?? $acf_name);
    $acf_input = $acf_input_type((string) ($acf_field['type'] ?? 'text'));
    if ($acf_key === '') {
        continue;
    }
    ?>
			<p class="form-field acf-group__field">
				<label>
					<?php 
    echo \esc_html($acf_label);
    ?>
					<code><?php 
    echo \esc_html($acf_name);
    ?></code>
				</label>
				<?php 
    if ($acf_input === 'textarea') {
        ?>
					<textarea
						name="<?php 
        echo \esc_attr($name_prefix) . '[' . \esc_attr($acf_key) . ']';
        ?>"
						class="width-100"
						placeholder="<?php 
        echo \esc_attr__('Drag & drop field here', 'dropshipping-xml-for-woocommerce');
        ?>"
					><?php 
        echo \esc_textarea($get_value($acf_key));
        ?></textarea>
				<?php 
    } else {
        ?>
					<input
						type="<?php 
        echo \esc_attr($acf_input);
        ?>"
						name="<?php 
        echo \esc_attr($name_prefix) . '[' . \esc_attr($acf_key) . ']';
        ?>"
						value="<?php 
        echo \esc_attr($get_value($acf_key));
        ?>"
						class="width-100"
						placeholder="<?php 
        echo \esc_attr__('Drag & drop field here', 'dropshipping-xml-for-woocommerce');
        ?>"
					/>
				<?php 
    }
    ?>
			</p>
		<?php 
}
?>
	</div>
</div>
<?php 
