<?php
namespace SabaiApps\Directories\Component\Map\CSVExporter;

use SabaiApps\Directories\Component\CSV\Exporter\AbstractExporter;
use SabaiApps\Directories\Component\Entity\Model\Field;

class MapCSVExporter extends AbstractExporter {

	public function csvExporterColumns( Field $field ) {
		switch ( $this->_name ) {
			case 'map_map':
				return array(
					'lat'  => __( 'Latitude', 'directories-pro' ),
					'lng'  => __( 'Longitude', 'directories-pro' ),
					'zoom' => __( 'Zoom Level', 'directories-pro' ),
				);
		}
		return parent::csvExporterColumns( $field );
	}

	public function csvExporterSettingsForm( Field $field, array $settings, $column, $enclosure, array $parents = array() ) {
		switch ( $this->_name ) {
			case 'map_map':
				return $this->_acceptMultipleValues( $field, $enclosure, $parents );
		}
	}

	public function csvExporterDoExport( Field $field, array $settings, $value, array $columns, array &$formStorage, array &$logs ) {
		switch ( $this->_name ) {
			case 'map_map':
				$ret = array();
				foreach ( $columns as $column ) {
					if ( ! isset( $settings['_separator'] ) ) {
						$ret[ $column ] = $value[0][ $column ];
					} else {
						foreach ( $value as $i => $_value ) {
							$ret[ $column ][ $i ] = $_value[ $column ];
						}
						$ret[ $column ] = implode( $settings[ $column ]['_separator'], $ret[ $column ] );
					}
				}
				return $ret;
		}
	}
}
