---
import { Image } from 'astro:assets';
import { getHighestWeightedLanguage, getLocales, getName } from '../lib/utils/langDriver';

interface Props {
    category: string;
    id: string;
    level: string;
    name: string;
    description: string;
    image: string;
    button_type: string;
    button_name: string;
    has_amount_input?: string;
}

const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')));
---
<div class="item-card" data-id={Astro.props.id}>
    <Image class="item-card-image" src={Astro.props.image} alt={Astro.props.id} width={512} height={512} />
    <div class="item-card-main-field">
        <form method="post">
            <input type="hidden" name="id" value={Astro.props.id} />
            <div class="item-card-name">{Astro.props.name} | {Astro.props.level}</div>
            <div class="item-card-description">{Astro.props.description} <a href={`/wiki/${Astro.props.category}/${Astro.props.id}`}>[more]</a></div>
            {Astro.props.button_name === "nav-researched" ?
            <input type="submit" class="item-card-build" value={getName(lang, Astro.props.button_type, "nav-researched")} disabled /> :
            <input type="submit" class="item-card-build" value={getName(lang, Astro.props.button_type, "nav-research")} />}
            <div class="item-card-info-button">i</div>
            {Astro.props.has_amount_input === "true" && <input type="number" name="amount" />}
        </form>
    </div>
</div>
<style>
.item-card {
    background-color: #fff;
    color: #333;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: row;
    width: 49%;
}

.item-card-expanded {
    height: auto;
} 

.item-card-image {
    width: 150px;
    height: 150px;
    margin: 4px;
    border-radius: 8px;
    object-fit: cover;
}

.item-card-main-field {
    background-color: #ccc;
    width: 100%;
    margin: 4px;
    border-radius: 8px;
    padding-left: 8px;
    padding-right: 100px;
}

.item-card-name {
    font-size: 48px;
}

.item-card-description {
    font-size: 24px;
    margin-top: 16px;
    margin-bottom: 16px;
}

.item-card-build {
    background-color: #333;
    color: #fff;
    border-radius: 8px;
    padding: 8px 16px;
    display: inline-block;
    margin-top: 16px;
    position: absolute;
    bottom: 16px;
    right: 16px;
}

.item-card-info-button {
    background-color: #333;
    color: #fff;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 16px;
    right: 16px;
    cursor: pointer;
}
</style>