<?php namespace BulkPriceEditor\ProductsTable\Columns;

use BulkPriceEditor\ProductsTable\WPListProductsTable;
use WC_Product;

class DateColumn extends Column {
	
	public function getSlug(): string {
		return 'date';
	}
	
	public function getName(): string {
		return __( 'Date', 'bulk-price-editor' );
	}
	
	public function render( WC_Product $product, WPListProductsTable $table ): string {
		// translators: %1$s: date, %2$s: time
		$date = sprintf( __( '%1$s at %2$s', 'bulk-price-editor' ), $product->get_date_created()->format( 'Y/m/d' ),
			$product->get_date_created()->format( 'g:i a' ) );
		
		switch ( $product->get_status() ) {
			case 'publish':
				$status = __( 'Published' );
				break;
			case 'future':
				$status = __( 'Scheduled' );
				break;
			case 'draft':
				$status = __( 'Draft' );
				break;
			case 'pending':
				$status = __( 'Pending Review' );
				break;
			case 'private':
				$status = __( 'Private' );
				break;
			case 'trash':
				$status = __( 'Trash' );
				break;
			default:
				$status = __( 'Unknown' );
		}
		
		return $status . '<br>' . $date;
	}
	
	public function sortable(): bool {
		return true;
	}
}
