<?php
namespace FinchCart\Frontend;

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

/**
 * Plugin Inline CSS
 */
class InlineScripts {

	/**
	 * Custom inline styles.
	 *
	 * @return string
	 */
	public function custom_inline_css() {
		$custom_css                 = '';
		$settings                   = get_option( 'finchcart_settings_' );
		$grid_columns               = isset( $settings['finchcart_grid_columns'] ) ? (array) wp_unslash( $settings['finchcart_grid_columns'] ) : '';
		$grid_columns_desktop       = isset( $grid_columns['finchcart_grid_columns_desktop'] ) ? absint( $grid_columns['finchcart_grid_columns_desktop'] ) : 5;
		$grid_columns_small_desktop = isset( $grid_columns['finchcart_grid_columns_small_desktop'] ) ? absint( $grid_columns['finchcart_grid_columns_small_desktop'] ) : 4;
		$grid_columns_tablet        = isset( $grid_columns['finchcart_grid_columns_tablet'] ) ? absint( $grid_columns['finchcart_grid_columns_tablet'] ) : 3;
		$grid_columns_large_mobile  = isset( $grid_columns['finchcart_grid_columns_large_mobile'] ) ? absint( $grid_columns['finchcart_grid_columns_large_mobile'] ) : 2;
		$grid_columns_mobile        = isset( $grid_columns['finchcart_grid_columns_mobile'] ) ? absint( $grid_columns['finchcart_grid_columns_mobile'] ) : 1;

		$list_columns               = isset( $settings['finchcart_list_columns'] ) ? (array) wp_unslash( $settings['finchcart_list_columns'] ) : '';
		$list_columns_desktop       = isset( $list_columns['finchcart_list_columns_desktop'] ) ? absint( $list_columns['finchcart_list_columns_desktop'] ) : 3;
		$list_columns_small_desktop = isset( $list_columns['finchcart_list_columns_small_desktop'] ) ? absint( $list_columns['finchcart_list_columns_small_desktop'] ) : 2;
		$list_columns_tablet        = isset( $list_columns['finchcart_list_columns_tablet'] ) ? absint( $list_columns['finchcart_list_columns_tablet'] ) : 2;
		$list_columns_large_mobile  = isset( $list_columns['finchcart_list_columns_large_mobile'] ) ? absint( $list_columns['finchcart_list_columns_large_mobile'] ) : 1;
		$list_columns_mobile        = isset( $list_columns['finchcart_list_columns_mobile'] ) ? absint( $list_columns['finchcart_list_columns_mobile'] ) : 1;

		$custom_css .= "
        .finchcart-modal-products-grid {
            grid-template-columns: repeat({$grid_columns_desktop}, 1fr);
        }";

		$custom_css .= "
        @media (max-width: 900px) {
        .finchcart-modal-products-grid {
            grid-template-columns: repeat({$grid_columns_small_desktop}, 1fr);
        }}";

		$custom_css .= "
        @media (max-width: 768px) {
        .finchcart-modal-products-grid {
            grid-template-columns: repeat({$grid_columns_tablet}, 1fr);
        }}";

		$custom_css .= "
        @media (max-width: 500px) {
        .finchcart-modal-products-grid {
            grid-template-columns: repeat({$grid_columns_large_mobile}, 1fr);
        }}";

		$custom_css .= "
        @media (max-width: 400px) {
        .finchcart-modal-products-grid {
            grid-template-columns: repeat({$grid_columns_mobile}, 1fr);
        }}";

		$custom_css .= "
        .finchcart-modal-products-list {
            grid-template-columns: repeat({$list_columns_desktop}, 1fr);
        }";

		$custom_css .= "
        @media (max-width: 900px) {
        .finchcart-modal-products-list {
            grid-template-columns: repeat({$list_columns_small_desktop}, 1fr);
        }}";

		$custom_css .= "
        @media (max-width: 768px) {
        .finchcart-modal-products-list {
            grid-template-columns: repeat({$list_columns_tablet}, 1fr);
        }}";

		$custom_css .= "
        @media (max-width: 500px) {
        .finchcart-modal-products-list {
            grid-template-columns: repeat({$list_columns_large_mobile}, 1fr);
        }}";

		$custom_css .= "
        @media (max-width: 400px) {
        .finchcart-modal-products-list {
            grid-template-columns: repeat({$list_columns_mobile}, 1fr);
        }}";

		return $custom_css;
	}
}
