import {
  type Meta,
  type StoryObj,
  applicationConfig,
  argsToTemplate,
} from '@storybook/angular';

import { AddressComponent, Address } from '@isa/shared/address';
import { CountryResource } from '@isa/crm/data-access';

const meta: Meta<AddressComponent> = {
  title: 'shared/address/AddressComponent',
  component: AddressComponent,
  decorators: [
    applicationConfig({
      providers: [
        {
          provide: CountryResource,
          useValue: {
            resource: {
              value: () => [
                { isO3166_A_3: 'DEU', name: 'Germany' },
                { isO3166_A_3: 'FRA', name: 'France' },
                { isO3166_A_3: 'AUT', name: 'Austria' },
                { isO3166_A_3: 'USA', name: 'United States' },
                { isO3166_A_3: 'CHE', name: 'Switzerland' },
                { isO3166_A_3: 'ITA', name: 'Italy' },
                { isO3166_A_3: 'ESP', name: 'Spain' },
              ],
            },
          },
        },
      ],
    }),
  ],
  argTypes: {
    address: {
      control: 'object',
      description: 'The address object to display',
    },
  },
  render: (args) => ({
    props: args,
    template: `<shared-address ${argsToTemplate(args)}></shared-address>`,
  }),
};

export default meta;

type Story = StoryObj<AddressComponent>;

export const Default: Story = {
  args: {
    address: {
      careOf: 'John Doe',
      street: 'Hauptstraße',
      streetNumber: '42',
      apartment: 'Apt 3B',
      info: 'Building A, 3rd Floor',
      zipCode: '10115',
      city: 'Berlin',
      country: 'DEU',
    },
  },
};

export const GermanAddress: Story = {
  args: {
    address: {
      street: 'Maximilianstraße',
      streetNumber: '15',
      zipCode: '80539',
      city: 'München',
      country: 'DEU',
    },
  },
};

export const FrenchAddress: Story = {
  args: {
    address: {
      street: 'Rue de la Paix',
      streetNumber: '25',
      zipCode: '75002',
      city: 'Paris',
      country: 'FRA',
    },
  },
};

export const AustrianAddress: Story = {
  args: {
    address: {
      street: 'Stephansplatz',
      streetNumber: '1',
      zipCode: '1010',
      city: 'Wien',
      country: 'AUT',
    },
  },
};

export const SwissAddress: Story = {
  args: {
    address: {
      street: 'Bahnhofstrasse',
      streetNumber: '50',
      zipCode: '8001',
      city: 'Zürich',
      country: 'CHE',
    },
  },
};

export const WithCareOf: Story = {
  args: {
    address: {
      careOf: 'Maria Schmidt',
      street: 'Berliner Straße',
      streetNumber: '100',
      zipCode: '60311',
      city: 'Frankfurt am Main',
      country: 'DEU',
    },
  },
};

export const WithApartment: Story = {
  args: {
    address: {
      street: 'Lindenallee',
      streetNumber: '23',
      apartment: 'Wohnung 5A',
      zipCode: '50668',
      city: 'Köln',
      country: 'DEU',
    },
  },
};

export const WithAdditionalInfo: Story = {
  args: {
    address: {
      street: 'Industriestraße',
      streetNumber: '7',
      info: 'Hintereingang, 2. Stock rechts',
      zipCode: '70565',
      city: 'Stuttgart',
      country: 'DEU',
    },
  },
};

export const MinimalAddress: Story = {
  args: {
    address: {
      street: 'Dorfstraße',
      city: 'Neustadt',
    },
  },
};

export const CompleteInternational: Story = {
  args: {
    address: {
      careOf: 'Jane Smith',
      street: 'Fifth Avenue',
      streetNumber: '350',
      apartment: 'Suite 2000',
      info: 'Empire State Building',
      zipCode: '10118',
      city: 'New York',
      state: 'NY',
      country: 'USA',
    },
  },
};

export const EmptyAddress: Story = {
  args: {
    address: {},
  },
};