import directus from "./directus";
import { readItems } from "@directus/sdk";

export const campaigns = await directus.request(
    readItems("codyops_campaigns", {
        fields: ['*']
        }
    )
);

export const currencies = await directus.request(
    readItems("codyops_currencies", {
        fields: ['*']
        }
    )
);


export function getAllCampaigns() {
    return campaigns;
};

export function getPrices(tier: string, currency: string) {
    const campaign = campaigns.filter((campaign) => campaign.status === 'published');
    const price = (campaign[0][tier] * currencies[currency] * (100 - campaign[0].discount ) / 100).toFixed(2);
    return { price, discount: campaign[0].discount };
}
