<commit_before>import * as Vue from 'vue';
import * as Vuex from 'vuex';
import { parse } from 'qs';

import { appStore } from '../../lib/gj-lib-client/vue/services/app/app-store';
import { Api } from '../../lib/gj-lib-client/components/api/api.service';
import { Game } from '../../lib/gj-lib-client/components/game/game.model';
import { User } from '../../lib/gj-lib-client/components/user/user.model';
import { Sellable } from '../../lib/gj-lib-client/components/sellable/sellable.model';
import { SellablePricing } from '../../lib/gj-lib-client/components/sellable/pricing/pricing.model';
import { GamePackagePayloadModel } from '../../lib/gj-lib-client/components/game/package/package-payload.model';
import { GamePackageCardModel } from '../../lib/gj-lib-client/components/game/package/card/card.model';
import { GamePackage } from '../../lib/gj-lib-client/components/game/package/package.model';

Vue.use( Vuex );

export const Mutations = {
	invalidKey: 'invalidKey',
	setProcessing: 'setProcessing',
	setNotProcessing: 'setNotProcessing',
	setFailure: 'setFailure',
	clearFailure: 'clearFailure',
	bootstrap: 'bootstrap',
	setPayment: 'setPayment',
	setAddress: 'setAddress',
};

export const Actions = {
	bootstrap: 'bootstrap',
	checkout: 'checkout',
};

export class PaymentData {
	method: 'cc-stripe' | 'paypal' = 'cc-stripe';
	email = '';
	amount = 0;
}

export class AddressData {
	country = '';
	region = '';
	street1 = '';
	postcode = '';
}

export class StoreState
{
	sellableKey: string = parse( window.location.search.substring( 1 ) ).key;
	isLightTheme: boolean = parse( window.location.search.substring( 1 ) ).theme === 'light';
	isLoaded = false;
	isProcessing = false;
	view: 'AppDownload' | 'AppPayment' = 'AppDownload';

	hasInvalidKey = false;
	hasFailure?: string = undefined;

	game?: Game = undefined;
	developer?: User = undefined;
	sellable?: Sellable = undefined;
	package?: GamePackage = undefined;
	packagePayload?: GamePackagePayloadModel = undefined;
	packageCard?: GamePackageCardModel = undefined;
	addresses: any[] = [];
	minOrderAmount = 50;
	pricing?: SellablePricing = undefined;
	originalPricing?: SellablePricing = undefined;

	payment = new PaymentData();
	address = new AddressData();
}

export type Store = Vuex.Store<StoreState>;

export const store = new Vuex.Store<StoreState>( {
	modules: {
		app: appStore,
	},
	state: new StoreState(),
	getters: {
		price: ( state ) =>
		{
			return state.pricing && ((state.pricing.amount || state.minOrderAmount) / 100).toFixed( 2 );
		},
		originalPrice( state )
		{
			if ( !state.originalPricing ) {
				return undefined;
			}

			return (state.originalPricing.amount / 100).toFixed( 2 );
		}
	},
	mutations: {
		[Mutations.invalidKey]: state => state.hasInvalidKey = true,

		[Mutations.setFailure]: ( state, failure ) => state.hasFailure = failure,
		[Mutations.clearFailure]: state => state.hasFailure = undefined,

		[Mutations.setProcessing]: state => state.isProcessing = true,
		[Mutations.setNotProcessing]: state => state.isProcessing = false,

		[Mutations.bootstrap]( state, response: any )
		{
			state.game = new Game( response.game );
			state.developer = new User( state.game.developer );
			state.sellable = new Sellable( response.sellable );
			state.packagePayload = new GamePackagePayloadModel( response );
			state.packageCard = new GamePackageCardModel(
				state.packagePayload.releases,
				state.packagePayload.builds,
			);
			state.package = state.packagePayload.packages[0];

			state.addresses = response.billingAddresses || [];
			state.minOrderAmount = response.minOrderAmount || 50;

			if ( state.sellable.pricings.length ) {
				state.pricing = state.sellable.pricings[0];
				if ( state.pricing.promotional ) {
					state.originalPricing = state.sellable.pricings[1];
				}
			}

			if ( state.sellable!.type === Sellable.TYPE_PAID ) {
				state.view = 'AppPayment';
			}

			state.isLoaded = true;
		},

		[Mutations.setPayment]: ( state, payment: any ) => state.payment = payment,
		[Mutations.setAddress]: ( state, address: any ) => state.address = address,
	},
	actions: {<commit_msg>If the sellable is owned, show download.<commit_after>import * as Vue from 'vue';
import * as Vuex from 'vuex';
import { parse } from 'qs';

import { appStore } from '../../lib/gj-lib-client/vue/services/app/app-store';
import { Api } from '../../lib/gj-lib-client/components/api/api.service';
import { Game } from '../../lib/gj-lib-client/components/game/game.model';
import { User } from '../../lib/gj-lib-client/components/user/user.model';
import { Sellable } from '../../lib/gj-lib-client/components/sellable/sellable.model';
import { SellablePricing } from '../../lib/gj-lib-client/components/sellable/pricing/pricing.model';
import { GamePackagePayloadModel } from '../../lib/gj-lib-client/components/game/package/package-payload.model';
import { GamePackageCardModel } from '../../lib/gj-lib-client/components/game/package/card/card.model';
import { GamePackage } from '../../lib/gj-lib-client/components/game/package/package.model';

Vue.use( Vuex );

export const Mutations = {
	invalidKey: 'invalidKey',
	setProcessing: 'setProcessing',
	setNotProcessing: 'setNotProcessing',
	setFailure: 'setFailure',
	clearFailure: 'clearFailure',
	bootstrap: 'bootstrap',
	setPayment: 'setPayment',
	setAddress: 'setAddress',
};

export const Actions = {
	bootstrap: 'bootstrap',
	checkout: 'checkout',
};

export class PaymentData {
	method: 'cc-stripe' | 'paypal' = 'cc-stripe';
	email = '';
	amount = 0;
}

export class AddressData {
	country = '';
	region = '';
	street1 = '';
	postcode = '';
}

export class StoreState
{
	sellableKey: string = parse( window.location.search.substring( 1 ) ).key;
	isLightTheme: boolean = parse( window.location.search.substring( 1 ) ).theme === 'light';
	isLoaded = false;
	isProcessing = false;
	view: 'AppDownload' | 'AppPayment' = 'AppDownload';

	hasInvalidKey = false;
	hasFailure?: string = undefined;

	game?: Game = undefined;
	developer?: User = undefined;
	sellable?: Sellable = undefined;
	package?: GamePackage = undefined;
	packagePayload?: GamePackagePayloadModel = undefined;
	packageCard?: GamePackageCardModel = undefined;
	addresses: any[] = [];
	minOrderAmount = 50;
	pricing?: SellablePricing = undefined;
	originalPricing?: SellablePricing = undefined;

	payment = new PaymentData();
	address = new AddressData();
}

export type Store = Vuex.Store<StoreState>;

export const store = new Vuex.Store<StoreState>( {
	modules: {
		app: appStore,
	},
	state: new StoreState(),
	getters: {
		price: ( state ) =>
		{
			return state.pricing && ((state.pricing.amount || state.minOrderAmount) / 100).toFixed( 2 );
		},
		originalPrice( state )
		{
			if ( !state.originalPricing ) {
				return undefined;
			}

			return (state.originalPricing.amount / 100).toFixed( 2 );
		}
	},
	mutations: {
		[Mutations.invalidKey]: state => state.hasInvalidKey = true,

		[Mutations.setFailure]: ( state, failure ) => state.hasFailure = failure,
		[Mutations.clearFailure]: state => state.hasFailure = undefined,

		[Mutations.setProcessing]: state => state.isProcessing = true,
		[Mutations.setNotProcessing]: state => state.isProcessing = false,

		[Mutations.bootstrap]( state, response: any )
		{
			state.game = new Game( response.game );
			state.developer = new User( state.game.developer );
			state.sellable = new Sellable( response.sellable );
			state.packagePayload = new GamePackagePayloadModel( response );
			state.packageCard = new GamePackageCardModel(
				state.packagePayload.releases,
				state.packagePayload.builds,
			);
			state.package = state.packagePayload.packages[0];

			state.addresses = response.billingAddresses || [];
			state.minOrderAmount = response.minOrderAmount || 50;

			if ( state.sellable.pricings.length ) {
				state.pricing = state.sellable.pricings[0];
				if ( state.pricing.promotional ) {
					state.originalPricing = state.sellable.pricings[1];
				}
			}

			if ( state.sellable!.type === Sellable.TYPE_PAID && !state.sellable!.is_owned ) {
				state.view = 'AppPayment';
			}

			state.isLoaded = true;
		},

		[Mutations.setPayment]: ( state, payment: any ) => state.payment = payment,
		[Mutations.setAddress]: ( state, address: any ) => state.address = address,
	},
	actions: {
{'fraction_non_alphanumeric': 0.15423606082548877, 'fraction_numerical': 0.004586048756939416, 'mean_word_length': 4.053048780487805, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '79945', 'n_tokens_mistral': 2883, 'n_tokens_neox': 2644, 'n_words': 555}