#!/bin/bash
shopt -s nullglob
DIRS=( */ )
CURRENT="${PWD}"
for EACH in "${DIRS[@]}"
do
	if [[ -f "${EACH}/.INSTALL" ]]; then
		rm "${EACH}/.INSTALL"
	fi
	if [[ -d "${EACH}/usr/share/plasma/look-and-feel/" ]]; then
		cd "${EACH}/usr/share/plasma/look-and-feel/" || exit 1
		THEME=( * )
		cd "${CURRENT}"
		VERSION=$(echo "${EACH}"  | cut -d "-" -f4)
		echo "DIR: $EACH | VERSION:${VERSION} | Theme: ${THEME}"
		echo '{
    "KPackageStructure": "Plasma/LookAndFeel",
    "KPlugin": {
        "Authors": [
            {
                "Email": "theemahn@gmail.com",
                "Name": "TheeMahn"
            }
        ],
        "Category": "",
        "Description": "Ultimate Edition '${VERSION}' by TheeMahn",
        "Id": "'${THEME}'",
        "License": "GPLv2+",
        "Name": "Ultimate Edition '${VERSION}'",
        "Website": "https://archultimateedition.com/"
    }
}' > "${EACH}/usr/share/plasma/look-and-feel/${THEME}/metadata.json"
	echo '[Desktop Entry]
Comment=Ultimate Edition Arch Desktop Design Language by TheeMahn
Encoding=UTF-8
Keywords=Desktop;Workspace;Appearance;Look and Feel;Logout;Lock;Suspend;Shutdown;Hibernate;
Name=Ultimate Edition' ${VERSION}'

Type=Service

X-KDE-ServiceTypes=Plasma/LookAndFeel
X-KDE-ParentApp=
X-KDE-PluginInfo-Author=TheeMahn
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Email=theemahn@ultimateedition.info
X-KDE-PluginInfo-License=GPLv2+
X-KDE-PluginInfo-Name='${THEME}'
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=https://www.ultimateedition.info
X-Plasma-MainScript=defaults
Name[C]=Ultimate Edition '${VERSION}'
Name[en_US]=Ultimate Edition '${VERSION} > "${EACH}/usr/share/plasma/look-and-feel/${THEME}/metadata.desktop"
#DESKTOP THEME
	if [[ -d "${EACH}/usr/share/plasma/desktoptheme/" ]]; then
		cd "${EACH}/usr/share/plasma/desktoptheme/" || exit 1
		THEME=( * )
		cd "${CURRENT}"
		echo "DIR: $EACH | VERSION:${VERSION} | Theme: ${THEME}"
		echo '[ContrastEffect]
contrast=0.2
enabled=true
intensity=2.0
saturation=1.7

[Desktop Entry]
X-KDE-PluginInfo-Author=TheeMahn
X-KDE-PluginInfo-Category=Plasma Theme
X-KDE-PluginInfo-Email=theemahn@archultimateedition.com
X-KDE-PluginInfo-EnabledByDefault=true
X-KDE-PluginInfo-License=LGPL 2.1+
X-KDE-PluginInfo-Name=Ultimate Edition '${VERSION}'
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=https://archultimateedition.com
X-Plasma-API=5.0' > "${EACH}/usr/share/plasma/desktoptheme/${THEME}/metadata.desktop"
	echo '{
    "KPlugin": {
        "Authors": [
            {
                "Email": "theemahn@gmail.com",
                "Name": "TheeMahn"
            }
        ],
        "Category": "",
        "Description": "Ultimate Edition Arch by TheeMahn",
        "EnabledByDefault": true,
        "Id": "Ultimate Edition '${VERSION}'",
        "License": "LGPL",
        "Name": "Ultimate Edition '${VERSION}'",
        "Version": "6.22.0",
        "Website": "https://archultimateedition.com/"
    },
    "X-Plasma-API": "5.0"
}' > "${EACH}/usr/share/plasma/desktoptheme/${THEME}/metadata.json"
	fi
	cd "${CURRENT}"
	if [[ -d "${EACH}/usr/share/color-schemes/" ]]; then
		cd "${EACH}/usr/share/color-schemes/" || exit 1
		files=(*.colors)

		cd "${CURRENT}"
		echo "DIR: $EACH | VERSION:${VERSION} | FILES: ${files}"
		cp "${EACH}/usr/share/color-schemes/${files}" "${EACH}/usr/share/plasma/desktoptheme/${THEME}/colors"
	fi
fi
done

shopt -u nullglob
