<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
  xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  x:Class="FrymasterBadgeApp.CompanyPage"
  Title="Manage Companies"
  BackgroundColor="#f1f5f9"
>
  <Grid ColumnDefinitions="350,*" Padding="20">
    <!-- Left: Company List -->
    <Frame
      BackgroundColor="White"
      BorderColor="#e2e8f0"
      CornerRadius="12"
      HasShadow="True"
      Padding="0"
    >
      <VerticalStackLayout>
        <Label
          Text="Companies"
          FontSize="18"
          FontAttributes="Bold"
          Margin="15"
          TextColor="#1e293b"
        />
        <CollectionView
          x:Name="CompanyList"
          SelectionMode="Single"
          SelectionChanged="OnCompanySelected"
          Margin="10"
        >
          <CollectionView.ItemTemplate>
            <DataTemplate>
              <Frame BackgroundColor="#f8fafc" CornerRadius="8" Padding="12" Margin="5">
                <Label Text="{Binding [Name]}" FontSize="16" TextColor="#1e293b" />
              </Frame>
            </DataTemplate>
          </CollectionView.ItemTemplate>
        </CollectionView>
      </VerticalStackLayout>
    </Frame>

    <!-- Right: Edit Form -->
    <ScrollView Grid.Column="1" Margin="30,0,0,0">
      <VerticalStackLayout Spacing="25" HorizontalOptions="Start" WidthRequest="700">
        <Button
          Text="+ Add New Company"
          Clicked="OnAddNewClicked"
          BackgroundColor="#10b981"
          TextColor="White"
          FontAttributes="Bold"
          CornerRadius="12"
          HeightRequest="50"
        />

        <Frame BackgroundColor="White" CornerRadius="16" HasShadow="True" Padding="30">
          <VerticalStackLayout Spacing="20">
            <Label Text="Company Logo" FontSize="16" FontAttributes="Bold" TextColor="#1e293b" />

            <HorizontalStackLayout HorizontalOptions="Center" Spacing="20">
              <Frame BackgroundColor="#f1f5f9" CornerRadius="8" Padding="0">
                <Image
                  x:Name="LogoPreview"
                  HeightRequest="120"
                  WidthRequest="240"
                  Aspect="AspectFit"
                />
              </Frame>
            </HorizontalStackLayout>

            <Button
              Text="Choose Logo Image"
              Clicked="OnSelectLogoClicked"
              BackgroundColor="#64748b"
              TextColor="White"
              CornerRadius="10"
            />

            <VerticalStackLayout Spacing="15">
              <Label Text="Company Name" TextColor="#475569" />
              <Entry x:Name="CompName" Placeholder="Enter name" />

              <Label Text="Street Address" TextColor="#475569" />
              <Entry x:Name="CompAddress" Placeholder="Enter address" />

              <Grid ColumnDefinitions="*,100,150" ColumnSpacing="15">
                <VerticalStackLayout Grid.Column="0">
                  <Label Text="City" TextColor="#475569" />
                  <Entry x:Name="CompCity" Placeholder="City" />
                </VerticalStackLayout>
                <VerticalStackLayout Grid.Column="1">
                  <Label Text="State" TextColor="#475569" />
                  <Entry x:Name="CompState" Placeholder="ST" />
                </VerticalStackLayout>
                <VerticalStackLayout Grid.Column="2">
                  <Label Text="Zip" TextColor="#475569" />
                  <Entry x:Name="CompZip" Placeholder="Zip" />
                </VerticalStackLayout>
              </Grid>
            </VerticalStackLayout>

            <Grid ColumnDefinitions="*,*" ColumnSpacing="20">
              <Button
                Text="Save Company"
                Clicked="OnSaveClicked"
                BackgroundColor="#2563eb"
                TextColor="White"
                FontAttributes="Bold"
                CornerRadius="12"
              />
              <Button
                Text="Delete Company"
                Clicked="OnDeleteClicked"
                BackgroundColor="#ef4444"
                TextColor="White"
                FontAttributes="Bold"
                CornerRadius="12"
              />
            </Grid>
          </VerticalStackLayout>
        </Frame>
      </VerticalStackLayout>
    </ScrollView>
  </Grid>
</ContentPage>
