<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="FrymasterBadgeApp.CompanyPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    Title="Company Settings">

    <Grid ColumnDefinitions="350, *">
        <Border
            Grid.Column="0"
            Margin="10"
            Style="{StaticResource CardStyle}">
            <VerticalStackLayout Padding="10" Spacing="10">
                <Label
                    FontAttributes="Bold"
                    FontSize="18"
                    Text="Registered Companies" />
                <Button
                    BackgroundColor="{StaticResource Success}"
                    Clicked="OnAddNewClicked"
                    Text="+ Add New"
                    TextColor="White" />

                <CollectionView
                    x:Name="CompanyList"
                    SelectionChanged="OnCompanySelectionChanged"
                    SelectionMode="Single">
                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <Grid Padding="10">
                                <Label
                                    FontSize="16"
                                    Text="{Binding [Name]}"
                                    VerticalOptions="Center" />
                            </Grid>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>
            </VerticalStackLayout>
        </Border>

        <ScrollView Grid.Column="1">
            <VerticalStackLayout Padding="30" Spacing="25">
                <Label
                    FontAttributes="Bold"
                    FontSize="24"
                    Text="Edit Company Details"
                    TextColor="{StaticResource Primary}" />

                <Border Padding="25" Style="{StaticResource CardStyle}">
                    <VerticalStackLayout Spacing="20">

                        <Grid ColumnDefinitions="100, *" ColumnSpacing="15">
                            <VerticalStackLayout Grid.Column="1" Spacing="5">
                                <Label
                                    FontAttributes="Bold"
                                    FontSize="12"
                                    Text="Company Name"
                                    TextColor="{StaticResource Primary}" />
                                <Entry x:Name="CompName" Placeholder="Required" />
                            </VerticalStackLayout>
                        </Grid>

                        <VerticalStackLayout Spacing="5">
                            <Label
                                FontAttributes="Bold"
                                FontSize="12"
                                Text="Street Address"
                                TextColor="{StaticResource Primary}" />
                            <Entry x:Name="CompAddress" Placeholder="123 Main St" />
                        </VerticalStackLayout>

                        <Grid ColumnDefinitions="*, 100, 150" ColumnSpacing="15">
                            <VerticalStackLayout Grid.Column="0" Spacing="5">
                                <Label
                                    FontAttributes="Bold"
                                    FontSize="12"
                                    Text="City"
                                    TextColor="{StaticResource Primary}" />
                                <Entry x:Name="CompCity" Placeholder="City Name" />
                            </VerticalStackLayout>

                            <VerticalStackLayout Grid.Column="1" Spacing="5">
                                <Label
                                    FontAttributes="Bold"
                                    FontSize="12"
                                    Text="State"
                                    TextColor="{StaticResource Primary}" />
                                <Entry
                                    x:Name="CompState"
                                    HorizontalTextAlignment="Center"
                                    MaxLength="2"
                                    Placeholder="ST" />
                            </VerticalStackLayout>

                            <VerticalStackLayout Grid.Column="2" Spacing="5">
                                <Label
                                    FontAttributes="Bold"
                                    FontSize="12"
                                    Text="Zip Code"
                                    TextColor="{StaticResource Primary}" />
                                <Entry
                                    x:Name="CompZip"
                                    Keyboard="Numeric"
                                    Placeholder="12345" />
                            </VerticalStackLayout>
                        </Grid>

                        <VerticalStackLayout Spacing="10">
                            <Label
                                FontAttributes="Bold"
                                FontSize="12"
                                Text="Company Logo"
                                TextColor="{StaticResource Primary}" />
                            <Grid ColumnDefinitions="Auto, *" ColumnSpacing="20">
                                <Border
                                    Grid.Column="0"
                                    Padding="5"
                                    HeightRequest="100"
                                    Style="{StaticResource CardStyle}"
                                    WidthRequest="100">
                                    <Image x:Name="LogoPreview" Aspect="AspectFit" />
                                </Border>
                                <VerticalStackLayout
                                    Grid.Column="1"
                                    Spacing="10"
                                    VerticalOptions="Center">
                                    <Label
                                        x:Name="LogoPathLabel"
                                        FontSize="11"
                                        Text="No logo selected"
                                        TextColor="{StaticResource Gray500}" />
                                    <Button
                                        BackgroundColor="{StaticResource Secondary}"
                                        Clicked="OnSelectLogoClicked"
                                        HorizontalOptions="Start"
                                        Text="Browse for Logo"
                                        TextColor="White" />
                                </VerticalStackLayout>
                            </Grid>
                        </VerticalStackLayout>

                        <BoxView
                            Margin="0,10"
                            HeightRequest="1"
                            Color="{StaticResource Gray500}" />

                        <HorizontalStackLayout HorizontalOptions="End" Spacing="15">
                            <Button
                                x:Name="DeleteBtn"
                                BackgroundColor="{StaticResource Danger}"
                                Clicked="OnDeleteClicked"
                                Text="Delete Company"
                                TextColor="White"
                                WidthRequest="150" />
                            <Button
                                BackgroundColor="{StaticResource Success}"
                                Clicked="OnSaveClicked"
                                FontAttributes="Bold"
                                Text="Save Changes"
                                TextColor="White"
                                WidthRequest="200" />
                        </HorizontalStackLayout>
                    </VerticalStackLayout>
                </Border>
            </VerticalStackLayout>
        </ScrollView>
    </Grid>
</ContentPage>
