#!/bin/bash
if [[ "$1" == 'options' ]] || [[ "$1" == 'o' ]]; then
	echo -e "c \t ==> \t compile"
	echo -e "d \t ==> \t static content deploy"
	echo -e "p \t ==> \t set permissions to folders var pub/static generated"
	echo -e "o \t ==> \t displays tools options"
	echo -e "st \t ==> \t activate template hints"
	echo -e "ut \t ==> \t deactivate template hints"
else
	if [[ "$1" == 'c' ]] || [[ "$2" == 'c' ]]; then
		sudo chmod -R 777 var generated pub/static
		php bin/magento setup:upgrade
		php bin/magento setup:di:compile
	fi
	if [[ "$1" == 'd' ]] || [[ "$2" == 'd' ]]; then
		sudo chmod -R 777 var generated pub/static
		rm -rf pub/static/_cache/ pub/static/frontend/ pub/static/adminhtml/
		echo "Removed pub static files"
		sudo chmod -R 777 var generated pub/static
		rm -rf var/view_preprocessed/pub/static/
		echo "Removed view preprocessed files"
		
		if [[ "$2" == 'en' ]] || [[ "$3" == 'en' ]]; then
			php bin/magento setup:static-content:deploy en_US --exclude-theme Magento/blank -f
		elif [[ "$2" == 'es' ]] || [[ "$3" == 'es' ]]; then
			php bin/magento setup:static-content:deploy es_ES --exclude-theme Magento/blank -f
		elif [[ "$2" == 'ca' ]] || [[ "$3" == 'ca' ]]; then
			php bin/magento setup:static-content:deploy ca_ES --exclude-theme Magento/blank -f
		elif [[ "$2" == 'all' ]] || [[ "$3" == 'all' ]]; then
			php bin/magento setup:static-content:deploy en_US es_ES ca_ES --exclude-theme Magento/blank -f
		else
			php bin/magento setup:static-content:deploy --exclude-theme Magento/blank --exclude-theme Magento/luma -f
		fi
		echo "Deployed static content"
	fi

	if [[ "$1" == 'st' ]]; then
		sudo chmod 777 -R var/
		php bin/magento dev:template-hints:enable
	fi
	if [[ "$1" == 'ut' ]]; then
		sudo chmod 777 -R var/
		php bin/magento dev:template-hints:disable
	fi
	if [[ "$1" == 'p' ]]; then
		sudo chmod -R 777 var generated pub/static
		echo "Permissions 777 set to var generated pub/static folders"
		exit
	fi
	sudo chmod -R 777 var generated pub/static
	php bin/magento cache:clean
	sudo chmod -R 777 var generated pub/static
	php bin/magento cache:flush
	sudo chmod -R 777 var generated pub/static
	sudo chmod -R 777 var generated pub/static
fi
